+ for (n_loops = 0; n_loops < 100; n_loops++) {
+ ovs_be64 x = htonll(0);
+ int i;
+
+ for (i = 0; i < 64; i++) {
+ ovs_be64 bit;
+ int ofs, n;
+
+ /* Change a random 0-bit into a 1-bit. */
+ do {
+ bit = htonll(UINT64_C(1) << (random_uint32() % 64));
+ } while (x & bit);
+ x |= bit;
+
+ for (ofs = 0; ofs < 64; ofs++) {
+ for (n = 0; n <= 64 - ofs; n++) {
+ bool expect;
+ bool answer;
+
+ expect = (n == 64
+ ? x == 0
+ : !(x & htonll(((UINT64_C(1) << n) - 1)
+ << ofs)));
+ answer = bitwise_is_all_zeros(&x, sizeof x, ofs, n);
+ if (expect != answer) {
+ fprintf(stderr,
+ "bitwise_is_all_zeros(0x%016"PRIx64",8,%d,%d "
+ "returned %s instead of %s\n",
+ ntohll(x), ofs, n,
+ answer ? "true" : "false",
+ expect ? "true" : "false");
+ abort();
+ }
+ }
+ }
+ }
+ }
+}
+
+static void
+test_follow_symlinks(int argc, char *argv[])
+{
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ char *target = follow_symlinks(argv[i]);
+ puts(target);
+ free(target);
+ }
+}
+\f
+static const struct command commands[] = {
+ {"ctz", 0, 0, test_ctz},
+ {"log_2_floor", 0, 0, test_log_2_floor},
+ {"bitwise_copy", 0, 0, test_bitwise_copy},
+ {"bitwise_zero", 0, 0, test_bitwise_zero},
+ {"bitwise_one", 0, 0, test_bitwise_one},
+ {"bitwise_is_all_zeros", 0, 0, test_bitwise_is_all_zeros},
+ {"follow-symlinks", 1, INT_MAX, test_follow_symlinks},
+ {NULL, 0, 0, NULL},
+};
+
+int
+main(int argc, char *argv[])
+{
+ set_program_name(argv[0]);
+ run_command(argc - 1, argv + 1, commands);