Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Hafnium Authors. |
| 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame^] | 4 | * Use of this source code is governed by a BSD-style |
| 5 | * license that can be found in the LICENSE file or at |
| 6 | * https://opensource.org/licenses/BSD-3-Clause. |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <stdalign.h> |
Andrew Walbran | afabe85 | 2019-03-20 17:55:11 +0000 | [diff] [blame] | 10 | #include <stddef.h> |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 11 | #include <stdint.h> |
| 12 | #include <stdio.h> |
| 13 | #include <string.h> |
| 14 | #include <unistd.h> |
| 15 | |
| 16 | #include "hf/memiter.h" |
| 17 | |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 18 | #include "hftest_common.h" |
Andrew Walbran | 1e7c774 | 2019-12-13 17:10:02 +0000 | [diff] [blame] | 19 | #include "test/hftest.h" |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 20 | #include <sys/reboot.h> |
| 21 | |
| 22 | void test_main(int argc, const char *argv[]) |
| 23 | { |
Andrew Scull | 3c351e9 | 2020-01-28 11:26:05 +0000 | [diff] [blame] | 24 | static const char json_command[] = "json"; |
| 25 | static const char run_command[] = "run"; |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 26 | const char *command; |
| 27 | |
| 28 | if (argc < 2) { |
| 29 | HFTEST_LOG("Unable to parse command."); |
| 30 | return; |
| 31 | } |
| 32 | command = argv[1]; |
| 33 | |
| 34 | hftest_use_registered_list(); |
| 35 | |
Andrew Scull | 3c351e9 | 2020-01-28 11:26:05 +0000 | [diff] [blame] | 36 | if (strncmp(command, json_command, sizeof(json_command)) == 0) { |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 37 | hftest_json(); |
| 38 | return; |
| 39 | } |
| 40 | |
Andrew Scull | 3c351e9 | 2020-01-28 11:26:05 +0000 | [diff] [blame] | 41 | if (strncmp(command, run_command, sizeof(run_command)) == 0) { |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 42 | struct memiter suite_name; |
| 43 | struct memiter test_name; |
| 44 | |
| 45 | if (argc != 4) { |
| 46 | HFTEST_LOG("Unable to parse test."); |
| 47 | return; |
| 48 | } |
| 49 | |
Andrew Scull | 55baca6 | 2019-04-05 14:56:20 +0100 | [diff] [blame] | 50 | memiter_init(&suite_name, argv[2], strnlen_s(argv[2], 64)); |
| 51 | memiter_init(&test_name, argv[3], strnlen_s(argv[3], 64)); |
Andrew Walbran | afabe85 | 2019-03-20 17:55:11 +0000 | [diff] [blame] | 52 | hftest_run(suite_name, test_name, NULL); |
Andrew Walbran | bc342d4 | 2019-02-05 16:56:02 +0000 | [diff] [blame] | 53 | return; |
| 54 | } |
| 55 | |
| 56 | hftest_help(); |
| 57 | } |
| 58 | |
| 59 | int main(int argc, const char *argv[]) |
| 60 | { |
| 61 | test_main(argc, argv); |
| 62 | reboot(RB_POWER_OFF); |
| 63 | return 0; |
| 64 | } |