• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: LGPL-2.1
2 /*
3  * Copyright (C) 2020, VMware, Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
4  *
5  */
6 #include <libgen.h>
7 #include <stdio.h>
8 #include <unistd.h>
9 #include <getopt.h>
10 #include <stdlib.h>
11 
12 #include <CUnit/CUnit.h>
13 #include <CUnit/Basic.h>
14 
15 #include "trace-utest.h"
16 
17 enum unit_tests {
18 	RUN_NONE	= 0,
19 	RUN_TRACEFS	= (1 << 0),
20 	RUN_ALL		= 0xFFFF
21 };
22 
print_help(char ** argv)23 static void print_help(char **argv)
24 {
25 	printf("Usage: %s [OPTIONS]\n", basename(argv[0]));
26 	printf("\t-s, --silent\tPrint test summary\n");
27 	printf("\t-r, --run test\tRun specific test:\n");
28 	printf("\t\t  tracefs   run libtracefs tests\n");
29 	printf("\t-h, --help\tPrint usage information\n");
30 	exit(0);
31 }
32 
main(int argc,char ** argv)33 int main(int argc, char **argv)
34 {
35 	CU_BasicRunMode verbose = CU_BRM_VERBOSE;
36 	enum unit_tests tests = RUN_NONE;
37 
38 	for (;;) {
39 		int c;
40 		int index = 0;
41 		const char *opts = "+hsr:";
42 		static struct option long_options[] = {
43 			{"silent", no_argument, NULL, 's'},
44 			{"run", required_argument, NULL, 'r'},
45 			{"help", no_argument, NULL, 'h'},
46 			{NULL, 0, NULL, 0}
47 		};
48 
49 		c = getopt_long (argc, argv, opts, long_options, &index);
50 		if (c == -1)
51 			break;
52 		switch (c) {
53 		case 'r':
54 			if (strcmp(optarg, "tracefs") == 0)
55 				tests |= RUN_TRACEFS;
56 			else
57 				print_help(argv);
58 			break;
59 		case 's':
60 			verbose = CU_BRM_SILENT;
61 			break;
62 		case 'h':
63 		default:
64 			print_help(argv);
65 			break;
66 		}
67 	}
68 
69 	if (tests == RUN_NONE)
70 		tests = RUN_ALL;
71 
72 	if (CU_initialize_registry() != CUE_SUCCESS) {
73 		printf("Test registry cannot be initialized\n");
74 		return -1;
75 	}
76 
77 	if (tests & RUN_TRACEFS)
78 		test_tracefs_lib();
79 
80 	CU_basic_set_mode(verbose);
81 	CU_basic_run_tests();
82 	CU_cleanup_registry();
83 	return 0;
84 }
85