1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <inttypes.h> 20 #include <lk/compiler.h> 21 #include <stdbool.h> 22 #include <trusty_ipc.h> 23 24 /* 25 * This function returns a time in nanoseconds based on hardware counters 26 * it is expected to: 27 * - Be non-wrapping or have very long (years) roll-over period 28 * - Have a resolution below 100ns 29 */ 30 uint64_t get_current_time_ns(void); 31 32 #define PORT_TEST(suite_name, port_name_string) \ 33 __BEGIN_CDECLS \ 34 static bool run_##suite_name(struct unittest* test) { \ 35 return RUN_ALL_TESTS(); \ 36 } \ 37 \ 38 int main(void) { \ 39 static struct unittest test = { \ 40 .port_name = port_name_string, \ 41 .run_test = run_##suite_name, \ 42 }; \ 43 struct unittest* tests = &test; \ 44 return unittest_main(&tests, 1); \ 45 } \ 46 __END_CDECLS 47 48 __BEGIN_CDECLS 49 50 struct unittest { 51 const char* port_name; 52 bool (*run_test)(struct unittest* test); 53 handle_t _port_handle; 54 }; 55 56 int unittest_main(struct unittest** tests, size_t test_count); 57 58 __END_CDECLS 59