int main(int argc, char *argv[]) { unsigned int a, b, i, j; int c, d; unsigned char e, f; int num_failed = 0, num_all = 0; fprintf(stdout, "Testing constant time operations...\n"); for (i = 0; i < OSSL_NELEM(test_values); ++i) { a = test_values[i]; num_failed += test_is_zero(a); num_failed += test_is_zero_8(a); num_all += 2; for (j = 0; j < OSSL_NELEM(test_values); ++j) { b = test_values[j]; num_failed += test_binary_op(&constant_time_lt, "constant_time_lt", a, b, a < b); num_failed += test_binary_op_8(&constant_time_lt_8, "constant_time_lt_8", a, b, a < b); num_failed += test_binary_op(&constant_time_lt, "constant_time_lt_8", b, a, b < a); num_failed += test_binary_op_8(&constant_time_lt_8, "constant_time_lt_8", b, a, b < a); num_failed += test_binary_op(&constant_time_ge, "constant_time_ge", a, b, a >= b); num_failed += test_binary_op_8(&constant_time_ge_8, "constant_time_ge_8", a, b, a >= b); num_failed += test_binary_op(&constant_time_ge, "constant_time_ge", b, a, b >= a); num_failed += test_binary_op_8(&constant_time_ge_8, "constant_time_ge_8", b, a, b >= a); num_failed += test_binary_op(&constant_time_eq, "constant_time_eq", a, b, a == b); num_failed += test_binary_op_8(&constant_time_eq_8, "constant_time_eq_8", a, b, a == b); num_failed += test_binary_op(&constant_time_eq, "constant_time_eq", b, a, b == a); num_failed += test_binary_op_8(&constant_time_eq_8, "constant_time_eq_8", b, a, b == a); num_failed += test_select(a, b); num_all += 13; } } for (i = 0; i < OSSL_NELEM(signed_test_values); ++i) { c = signed_test_values[i]; for (j = 0; j < OSSL_NELEM(signed_test_values); ++j) { d = signed_test_values[j]; num_failed += test_select_int(c, d); num_failed += test_eq_int(c, d); num_failed += test_eq_int_8(c, d); num_all += 3; } } for (i = 0; i < sizeof(test_values_8); ++i) { e = test_values_8[i]; for (j = 0; j < sizeof(test_values_8); ++j) { f = test_values_8[j]; num_failed += test_select_8(e, f); num_all += 1; } } if (!num_failed) { fprintf(stdout, "ok (ran %d tests)\n", num_all); return EXIT_SUCCESS; } else { fprintf(stdout, "%d of %d tests failed!\n", num_failed, num_all); return EXIT_FAILURE; } }
int main(int argc, char *argv[]) { assert(sizeof(long long) == 8); int num_unary_tests = 0, num_binary_tests = 0; int num_ternary_tests = 0, num_qernary_tests = 0; for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "-v") == 0) ++verbose; else if (strcmp(argv[i], "--help") == 0) { printf("\nvbit-test [ -v | --help ]\n"); printf("\n\t-v verbose mode; show number of tests\n"); printf("\n\t-v -v verbose mode; shows IROps being tested\n"); printf("\n\t-v -v -v verbose mode, extreme edition\n\n"); return 0; } else { printf("%s ? Nothing happens.\n", argv[i]); return 1; } } if (! RUNNING_ON_VALGRIND) { fprintf(stderr, "*** This program needs to run under memcheck.\n"); return 1; } setbuf(stdout, NULL); // make stdout unbuffered fixup_irops(); // determine need for special handling // Iterate over all primops IROp first = Iop_INVALID + 1; IROp last = Iop_LAST; IROp opkind; if (0) { // overwrite for debugging first = Iop_CasCmpEQ8; last = first + 1; } // Iterate over all IROps in the enum type. That is the only way to // make sure the operator is tested on at least one platform. // Loop assumes no holes in the enumerator values for (opkind = first; opkind < last; ++opkind) { const irop_t *op = get_irop(opkind); if (op == NULL) continue; if (op->undef_kind == UNDEF_UNKNOWN) { fprintf(stderr, "...skipping %s; unknown undef propagation\n", op->name); continue; } test_data_t *data = new_test_data(op); if (verbose > 1) printf("Testing operator %s\n", op->name); IRICB iricb = new_iricb(op, data); valgrind_vex_init_for_iri(&iricb); switch (iricb.num_operands) { case 1: num_unary_tests += test_unary_op(op, data); break; case 2: num_binary_tests += test_binary_op(op, data); break; case 3: num_ternary_tests += test_ternary_op(op, data); break; case 4: num_qernary_tests += test_qernary_op(op, data); break; default: panic("operator not handled"); } free(data); } if (verbose) printf("\nvbit-test ran %d unary, %d binary, %d ternary and" " %d qernary tests.\n\n", num_unary_tests, num_binary_tests, num_ternary_tests, num_qernary_tests); return 0; }