tests/vlock-test.c: add missing error path
[vlock.git] / tests / vlock-test.c
blob73d7bd75fb3c3e5dec8c1f51c4f73ab174342bbb
1 #include <stdlib.h>
2 #include <stdio.h>
4 #include <CUnit/CUnit.h>
5 #include <CUnit/Basic.h>
7 #include "test_list.h"
8 #include "test_tsort.h"
9 #include "test_util.h"
10 #include "test_process.h"
12 CU_SuiteInfo vlock_test_suites[] = {
13 { "test_list" , NULL, NULL, list_tests },
14 { "test_tsort", NULL, NULL, tsort_tests },
15 { "test_util", NULL, NULL, util_tests },
16 { "test_process", NULL, NULL, process_tests },
17 CU_SUITE_INFO_NULL,
20 int main(int __attribute__((unused)) argc, const char *argv[])
22 char *output_mode = getenv("VLOCK_TEST_OUTPUT_MODE");
24 if (CU_initialize_registry() != CUE_SUCCESS) {
25 fprintf(stderr, "%s: CUnit initialization failed\n", argv[0]);
26 exit(EXIT_FAILURE);
29 if (CU_register_suites(vlock_test_suites) != CUE_SUCCESS) {
30 fprintf(stderr, "%s: registering test suites failed: %s\n", argv[0], CU_get_error_msg());
31 goto error;
34 if (output_mode != NULL) {
35 if (strcmp(output_mode, "verbose") == 0)
36 CU_basic_set_mode(CU_BRM_VERBOSE);
37 else if (strcmp(output_mode, "normal") == 0)
38 CU_basic_set_mode(CU_BRM_NORMAL);
39 else if (strcmp(output_mode, "silent") == 0)
40 CU_basic_set_mode(CU_BRM_SILENT);
43 if (CU_basic_run_tests() != CUE_SUCCESS) {
44 fprintf(stderr, "%s: running tests failed\n", argv[0]);
45 goto error;
48 if (CU_get_number_of_tests_failed() > 0)
49 goto error;
51 CU_cleanup_registry();
52 exit(EXIT_SUCCESS);
54 error:
55 CU_cleanup_registry();
56 exit(EXIT_FAILURE);