1*3c8a67f5SJiri Olsa #include <stdbool.h> 2*3c8a67f5SJiri Olsa #include "tests.h" 3*3c8a67f5SJiri Olsa #include "dso.h" 4*3c8a67f5SJiri Olsa #include "debug.h" 5*3c8a67f5SJiri Olsa 6*3c8a67f5SJiri Olsa static int test(const char *path, bool alloc_name, bool alloc_ext, 7*3c8a67f5SJiri Olsa bool kmod, bool comp, const char *name, const char *ext) 8*3c8a67f5SJiri Olsa { 9*3c8a67f5SJiri Olsa struct kmod_path m; 10*3c8a67f5SJiri Olsa 11*3c8a67f5SJiri Olsa memset(&m, 0x0, sizeof(m)); 12*3c8a67f5SJiri Olsa 13*3c8a67f5SJiri Olsa TEST_ASSERT_VAL("kmod_path__parse", 14*3c8a67f5SJiri Olsa !__kmod_path__parse(&m, path, alloc_name, alloc_ext)); 15*3c8a67f5SJiri Olsa 16*3c8a67f5SJiri Olsa pr_debug("%s - alloc name %d, alloc ext %d, kmod %d, comp %d, name '%s', ext '%s'\n", 17*3c8a67f5SJiri Olsa path, alloc_name, alloc_ext, m.kmod, m.comp, m.name, m.ext); 18*3c8a67f5SJiri Olsa 19*3c8a67f5SJiri Olsa TEST_ASSERT_VAL("wrong kmod", m.kmod == kmod); 20*3c8a67f5SJiri Olsa TEST_ASSERT_VAL("wrong comp", m.comp == comp); 21*3c8a67f5SJiri Olsa 22*3c8a67f5SJiri Olsa if (ext) 23*3c8a67f5SJiri Olsa TEST_ASSERT_VAL("wrong ext", m.ext && !strcmp(ext, m.ext)); 24*3c8a67f5SJiri Olsa else 25*3c8a67f5SJiri Olsa TEST_ASSERT_VAL("wrong ext", !m.ext); 26*3c8a67f5SJiri Olsa 27*3c8a67f5SJiri Olsa if (name) 28*3c8a67f5SJiri Olsa TEST_ASSERT_VAL("wrong name", m.name && !strcmp(name, m.name)); 29*3c8a67f5SJiri Olsa else 30*3c8a67f5SJiri Olsa TEST_ASSERT_VAL("wrong name", !m.name); 31*3c8a67f5SJiri Olsa 32*3c8a67f5SJiri Olsa free(m.name); 33*3c8a67f5SJiri Olsa free(m.ext); 34*3c8a67f5SJiri Olsa return 0; 35*3c8a67f5SJiri Olsa } 36*3c8a67f5SJiri Olsa 37*3c8a67f5SJiri Olsa #define T(path, an, ae, k, c, n, e) \ 38*3c8a67f5SJiri Olsa TEST_ASSERT_VAL("failed", !test(path, an, ae, k, c, n, e)) 39*3c8a67f5SJiri Olsa 40*3c8a67f5SJiri Olsa int test__kmod_path__parse(void) 41*3c8a67f5SJiri Olsa { 42*3c8a67f5SJiri Olsa /* path alloc_name alloc_ext kmod comp name ext */ 43*3c8a67f5SJiri Olsa T("/xxxx/xxxx/x-x.ko", true , true , true, false, "[x_x]", NULL); 44*3c8a67f5SJiri Olsa T("/xxxx/xxxx/x-x.ko", false , true , true, false, NULL , NULL); 45*3c8a67f5SJiri Olsa T("/xxxx/xxxx/x-x.ko", true , false , true, false, "[x_x]", NULL); 46*3c8a67f5SJiri Olsa T("/xxxx/xxxx/x-x.ko", false , false , true, false, NULL , NULL); 47*3c8a67f5SJiri Olsa 48*3c8a67f5SJiri Olsa /* path alloc_name alloc_ext kmod comp name ext */ 49*3c8a67f5SJiri Olsa T("/xxxx/xxxx/x.ko.gz", true , true , true, true, "[x]", "gz"); 50*3c8a67f5SJiri Olsa T("/xxxx/xxxx/x.ko.gz", false , true , true, true, NULL , "gz"); 51*3c8a67f5SJiri Olsa T("/xxxx/xxxx/x.ko.gz", true , false , true, true, "[x]", NULL); 52*3c8a67f5SJiri Olsa T("/xxxx/xxxx/x.ko.gz", false , false , true, true, NULL , NULL); 53*3c8a67f5SJiri Olsa 54*3c8a67f5SJiri Olsa /* path alloc_name alloc_ext kmod comp name ext */ 55*3c8a67f5SJiri Olsa T("/xxxx/xxxx/x.gz", true , true , false, true, "x.gz" ,"gz"); 56*3c8a67f5SJiri Olsa T("/xxxx/xxxx/x.gz", false , true , false, true, NULL ,"gz"); 57*3c8a67f5SJiri Olsa T("/xxxx/xxxx/x.gz", true , false , false, true, "x.gz" , NULL); 58*3c8a67f5SJiri Olsa T("/xxxx/xxxx/x.gz", false , false , false, true, NULL , NULL); 59*3c8a67f5SJiri Olsa 60*3c8a67f5SJiri Olsa /* path alloc_name alloc_ext kmod comp name ext */ 61*3c8a67f5SJiri Olsa T("x.gz", true , true , false, true, "x.gz", "gz"); 62*3c8a67f5SJiri Olsa T("x.gz", false , true , false, true, NULL , "gz"); 63*3c8a67f5SJiri Olsa T("x.gz", true , false , false, true, "x.gz", NULL); 64*3c8a67f5SJiri Olsa T("x.gz", false , false , false, true, NULL , NULL); 65*3c8a67f5SJiri Olsa 66*3c8a67f5SJiri Olsa /* path alloc_name alloc_ext kmod comp name ext */ 67*3c8a67f5SJiri Olsa T("x.ko.gz", true , true , true, true, "[x]", "gz"); 68*3c8a67f5SJiri Olsa T("x.ko.gz", false , true , true, true, NULL , "gz"); 69*3c8a67f5SJiri Olsa T("x.ko.gz", true , false , true, true, "[x]", NULL); 70*3c8a67f5SJiri Olsa T("x.ko.gz", false , false , true, true, NULL , NULL); 71*3c8a67f5SJiri Olsa 72*3c8a67f5SJiri Olsa return 0; 73*3c8a67f5SJiri Olsa } 74