1 // Copyright 2017 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <getopt.h>
6 #include <stdlib.h>
7 #include <blktest/blktest.h>
8 #include <unittest/unittest.h>
9 
print_usage(char * self)10 void print_usage(char* self) {
11     fprintf(stderr, "Usage: %s -d <blkdev_path>\n", self);
12 }
13 
main(int argc,char ** argv)14 int main(int argc, char** argv) {
15     int opt;
16     const char* blkdev = NULL;
17     while ((opt = getopt(argc, argv, "d:")) != -1) {
18         switch (opt) {
19         case 'd':
20             blkdev = optarg;
21             break;
22         default:
23             print_usage(argv[0]);
24             return 1;
25         }
26     }
27 
28     if (!blkdev) {
29         print_usage(argv[0]);
30         return 1;
31     }
32 
33     unsetenv(BLKTEST_BLK_DEV);
34     if (blkdev != NULL) {
35         setenv(BLKTEST_BLK_DEV, blkdev, 1);
36     }
37 
38     bool success = unittest_run_all_tests(argc, argv);
39 
40     unsetenv(BLKTEST_BLK_DEV);
41     return success ? 0 : -1;
42 }
43