diff options
-rw-r--r-- | include/my_pthread.h | 3 | ||||
-rw-r--r-- | mysys/my_gethwaddr.c | 32 | ||||
-rw-r--r-- | mysys/thr_mutex.c | 4 | ||||
-rw-r--r-- | unittest/examples/skip-t.c | 8 | ||||
-rw-r--r-- | unittest/examples/skip_all-t.c | 8 | ||||
-rw-r--r-- | unittest/examples/todo-t.c | 8 | ||||
-rw-r--r-- | unittest/mytap/t/basic-t.c | 2 | ||||
-rw-r--r-- | unittest/mytap/tap.c | 17 | ||||
-rw-r--r-- | unittest/mytap/tap.h | 15 |
9 files changed, 60 insertions, 37 deletions
diff --git a/include/my_pthread.h b/include/my_pthread.h index d3053b4861a..bec88a716fe 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -501,7 +501,8 @@ int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint line); int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file, uint line); int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp, - struct timespec *abstime, const char *file, uint line); + const struct timespec *abstime, + const char *file, uint line); void safe_mutex_global_init(void); void safe_mutex_end(FILE *file); diff --git a/mysys/my_gethwaddr.c b/mysys/my_gethwaddr.c index d14087d061e..ab44bac43d3 100644 --- a/mysys/my_gethwaddr.c +++ b/mysys/my_gethwaddr.c @@ -21,18 +21,6 @@ #ifndef MAIN -#if defined(__FreeBSD__) || defined(__linux__) -static my_bool memcpy_and_test(uchar *to, uchar *from, uint len) -{ - uint i, res=1; - - for (i=0; i < len; i++) - if ((*to++= *from++)) - res=0; - return res; -} -#endif /* FreeBSD || linux */ - #ifdef __FreeBSD__ #include <net/ethernet.h> @@ -44,10 +32,11 @@ static my_bool memcpy_and_test(uchar *to, uchar *from, uint len) my_bool my_gethwaddr(uchar *to) { size_t len; - uchar *buf, *next, *end, *addr; + char *buf, *next, *end; struct if_msghdr *ifm; struct sockaddr_dl *sdl; int res=1, mib[6]={CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0}; + char zero_array[ETHER_ADDR_LEN] = {0}; if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1) goto err; @@ -63,9 +52,9 @@ my_bool my_gethwaddr(uchar *to) ifm = (struct if_msghdr *)next; if (ifm->ifm_type == RTM_IFINFO) { - sdl = (struct sockaddr_dl *)(ifm + 1); - addr=(uchar *)LLADDR(sdl); - res=memcpy_and_test(to, addr, ETHER_ADDR_LEN); + sdl= (struct sockaddr_dl *)(ifm + 1); + memcpy(to, LLADDR(sdl), ETHER_ADDR_LEN); + res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1; } } @@ -81,8 +70,9 @@ err: my_bool my_gethwaddr(uchar *to) { - int fd, res=1; + int fd, res= 1; struct ifreq ifr; + char zero_array[ETHER_ADDR_LEN] = {0}; fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) @@ -91,9 +81,13 @@ my_bool my_gethwaddr(uchar *to) bzero(&ifr, sizeof(ifr)); strnmov(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name) - 1); - do { + do + { if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0) - res=memcpy_and_test(to, (uchar *)&ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); + { + memcpy(to, &ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); + res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1; + } } while (res && (errno == 0 || errno == ENODEV) && ifr.ifr_name[3]++ < '6'); close(fd); diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c index db35d5a13a6..00890bc0425 100644 --- a/mysys/thr_mutex.c +++ b/mysys/thr_mutex.c @@ -262,8 +262,8 @@ int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp, const char *file, int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp, - struct timespec *abstime, - const char *file, uint line) + const struct timespec *abstime, + const char *file, uint line) { int error; pthread_mutex_lock(&mp->global); diff --git a/unittest/examples/skip-t.c b/unittest/examples/skip-t.c index 092353fcc48..c8c910b31ff 100644 --- a/unittest/examples/skip-t.c +++ b/unittest/examples/skip-t.c @@ -18,11 +18,11 @@ int main() { plan(4); - ok(1, NULL); - ok(1, NULL); + ok1(1); + ok1(1); SKIP_BLOCK_IF(1, 2, "Example of skipping a few test points in a test") { - ok(1, NULL); - ok(1, NULL); + ok1(1); + ok1(1); } return exit_status(); } diff --git a/unittest/examples/skip_all-t.c b/unittest/examples/skip_all-t.c index 11c1ef13276..3751642293b 100644 --- a/unittest/examples/skip_all-t.c +++ b/unittest/examples/skip_all-t.c @@ -31,9 +31,9 @@ int main() { if (!has_feature()) skip_all("Example of skipping an entire test"); plan(4); - ok(1, NULL); - ok(1, NULL); - ok(1, NULL); - ok(1, NULL); + ok1(1); + ok1(1); + ok1(1); + ok1(1); return exit_status(); } diff --git a/unittest/examples/todo-t.c b/unittest/examples/todo-t.c index 027d6d6b65e..67bea51965c 100644 --- a/unittest/examples/todo-t.c +++ b/unittest/examples/todo-t.c @@ -21,15 +21,15 @@ int main() { plan(4); - ok(1, NULL); - ok(1, NULL); + ok1(1); + ok1(1); /* Tests in the todo region is expected to fail. If they don't, something is strange. */ todo_start("Need to fix these"); - ok(0, NULL); - ok(0, NULL); + ok1(0); + ok1(0); todo_end(); return exit_status(); } diff --git a/unittest/mytap/t/basic-t.c b/unittest/mytap/t/basic-t.c index c0ceb5bf190..b588521d192 100644 --- a/unittest/mytap/t/basic-t.c +++ b/unittest/mytap/t/basic-t.c @@ -22,7 +22,7 @@ int main() { plan(5); ok(1 == 1, "testing basic functions"); ok(2 == 2, " "); - ok(3 == 3, NULL); + ok1(3 == 3); if (1 == 1) skip(2, "Sensa fragoli"); else { diff --git a/unittest/mytap/tap.c b/unittest/mytap/tap.c index 7facb23e7e3..f7a6d881421 100644 --- a/unittest/mytap/tap.c +++ b/unittest/mytap/tap.c @@ -244,6 +244,23 @@ ok(int pass, char const *fmt, ...) emit_endl(); } +void +ok1(int const pass) +{ + va_list ap; + + memset(&ap, 0, sizeof(ap)); + + if (!pass && *g_test.todo == '\0') + ++g_test.failed; + + vemit_tap(pass, NULL, ap); + + if (*g_test.todo != '\0') + emit_dir("todo", g_test.todo); + + emit_endl(); +} void skip(int how_many, char const *fmt, ...) diff --git a/unittest/mytap/tap.h b/unittest/mytap/tap.h index 1f6edfbba07..60d39c42441 100644 --- a/unittest/mytap/tap.h +++ b/unittest/mytap/tap.h @@ -121,8 +121,8 @@ void plan(int const count); @endcode @param pass Zero if the test failed, non-zero if it passed. - @param fmt Format string in printf() format. NULL is allowed, in - which case nothing is printed. + @param fmt Format string in printf() format. NULL is not allowed, + use ok1() in this case. */ void ok(int const pass, char const *fmt, ...) @@ -130,6 +130,17 @@ void ok(int const pass, char const *fmt, ...) /** + Report test result as a TAP line. + + Same as ok() but does not take a message to be printed. + + @param pass Zero if the test failed, non-zero if it passed. +*/ + +void ok1(int const pass); + + +/** Skip a determined number of tests. Function to print that <em>how_many</em> tests have been skipped. |