Nikolai Artemiev | 702c58a | 2020-09-16 14:12:22 +1000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright 2020 Google LLC |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
Edward O'Callaghan | 46f2d4e | 2020-05-20 20:10:20 +1000 | [diff] [blame] | 15 | |
| 16 | #include <include/test.h> |
| 17 | #include "tests.h" |
| 18 | |
| 19 | #include <stdio.h> |
Anastasia Klimchuk | 98534e7 | 2021-04-23 15:47:03 +1000 | [diff] [blame] | 20 | #include <stdint.h> |
Edward O'Callaghan | 46f2d4e | 2020-05-20 20:10:20 +1000 | [diff] [blame] | 21 | |
| 22 | /* redefinitions/wrapping */ |
Anastasia Klimchuk | ab9d146 | 2021-04-19 14:47:35 +1000 | [diff] [blame] | 23 | #define LOG_ME printf("%s is called\n", __func__) |
| 24 | |
Edward O'Callaghan | 46f2d4e | 2020-05-20 20:10:20 +1000 | [diff] [blame] | 25 | void __wrap_physunmap(void *virt_addr, size_t len) |
| 26 | { |
Anastasia Klimchuk | ab9d146 | 2021-04-19 14:47:35 +1000 | [diff] [blame] | 27 | LOG_ME; |
Edward O'Callaghan | 46f2d4e | 2020-05-20 20:10:20 +1000 | [diff] [blame] | 28 | } |
Anastasia Klimchuk | ab9d146 | 2021-04-19 14:47:35 +1000 | [diff] [blame] | 29 | |
Edward O'Callaghan | 46f2d4e | 2020-05-20 20:10:20 +1000 | [diff] [blame] | 30 | void *__wrap_physmap(const char *descr, uintptr_t phys_addr, size_t len) |
| 31 | { |
Anastasia Klimchuk | ab9d146 | 2021-04-19 14:47:35 +1000 | [diff] [blame] | 32 | LOG_ME; |
Edward O'Callaghan | 46f2d4e | 2020-05-20 20:10:20 +1000 | [diff] [blame] | 33 | return NULL; |
| 34 | } |
| 35 | |
Anastasia Klimchuk | 98534e7 | 2021-04-23 15:47:03 +1000 | [diff] [blame] | 36 | void __wrap_sio_write(uint16_t port, uint8_t reg, uint8_t data) |
| 37 | { |
| 38 | LOG_ME; |
| 39 | } |
| 40 | |
| 41 | uint8_t __wrap_sio_read(uint16_t port, uint8_t reg) |
| 42 | { |
| 43 | LOG_ME; |
| 44 | return (uint8_t)mock(); |
| 45 | } |
| 46 | |
| 47 | int __wrap_open(const char *pathname, int flags) |
| 48 | { |
| 49 | LOG_ME; |
| 50 | return 2021; |
| 51 | } |
| 52 | |
| 53 | int __wrap_open64(const char *pathname, int flags) |
| 54 | { |
| 55 | LOG_ME; |
| 56 | return 2021; |
| 57 | } |
| 58 | |
| 59 | int __wrap_ioctl(int fd, unsigned long int request, ...) |
| 60 | { |
| 61 | LOG_ME; |
| 62 | return 2021; |
| 63 | } |
| 64 | |
| 65 | FILE *__wrap_fopen(const char *pathname, const char *mode) |
| 66 | { |
| 67 | LOG_ME; |
| 68 | return NULL; |
| 69 | } |
| 70 | |
| 71 | FILE *__wrap_fopen64(const char *pathname, const char *mode) |
| 72 | { |
| 73 | LOG_ME; |
| 74 | return NULL; |
| 75 | } |
| 76 | |
Edward O'Callaghan | 46f2d4e | 2020-05-20 20:10:20 +1000 | [diff] [blame] | 77 | int main(void) |
| 78 | { |
| 79 | int ret = 0; |
| 80 | |
Anastasia Klimchuk | ab9d146 | 2021-04-19 14:47:35 +1000 | [diff] [blame] | 81 | cmocka_set_message_output(CM_OUTPUT_STDOUT); |
| 82 | |
Edward O'Callaghan | 3cc70c2 | 2020-05-22 18:42:11 +1000 | [diff] [blame] | 83 | const struct CMUnitTest helpers_tests[] = { |
| 84 | cmocka_unit_test(address_to_bits_test_success), |
| 85 | cmocka_unit_test(bitcount_test_success), |
| 86 | cmocka_unit_test(minmax_test_success), |
| 87 | cmocka_unit_test(strcat_realloc_test_success), |
| 88 | cmocka_unit_test(tolower_string_test_success), |
| 89 | cmocka_unit_test(reverse_byte_test_success), |
| 90 | cmocka_unit_test(reverse_bytes_test_success), |
| 91 | }; |
| 92 | ret |= cmocka_run_group_tests_name("helpers.c tests", helpers_tests, NULL, NULL); |
| 93 | |
Edward O'Callaghan | 629b8f0 | 2020-05-22 16:46:52 +1000 | [diff] [blame] | 94 | const struct CMUnitTest flashrom_tests[] = { |
| 95 | cmocka_unit_test(flashbuses_to_text_test_success), |
| 96 | }; |
| 97 | ret |= cmocka_run_group_tests_name("flashrom.c tests", flashrom_tests, NULL, NULL); |
| 98 | |
Edward O'Callaghan | 41f48c7 | 2020-05-22 16:46:26 +1000 | [diff] [blame] | 99 | const struct CMUnitTest spi25_tests[] = { |
| 100 | cmocka_unit_test(spi_write_enable_test_success), |
| 101 | cmocka_unit_test(spi_write_disable_test_success), |
| 102 | cmocka_unit_test(probe_spi_rdid_test_success), |
| 103 | cmocka_unit_test(probe_spi_rdid4_test_success), |
| 104 | cmocka_unit_test(probe_spi_rems_test_success), |
| 105 | cmocka_unit_test(probe_spi_res1_test_success), |
| 106 | cmocka_unit_test(probe_spi_res2_test_success), |
| 107 | cmocka_unit_test(probe_spi_res3_test_success), |
| 108 | cmocka_unit_test(probe_spi_at25f_test_success), |
Edward O'Callaghan | 76d2445 | 2020-05-22 19:09:49 +1000 | [diff] [blame] | 109 | cmocka_unit_test(probe_spi_st95_test_success), /* spi95.c */ |
Edward O'Callaghan | 41f48c7 | 2020-05-22 16:46:26 +1000 | [diff] [blame] | 110 | }; |
| 111 | ret |= cmocka_run_group_tests_name("spi25.c tests", spi25_tests, NULL, NULL); |
| 112 | |
Anastasia Klimchuk | cffaac1 | 2021-04-21 07:58:30 +1000 | [diff] [blame] | 113 | const struct CMUnitTest init_shutdown_tests[] = { |
| 114 | cmocka_unit_test(dummy_init_and_shutdown_test_success), |
Anastasia Klimchuk | 98534e7 | 2021-04-23 15:47:03 +1000 | [diff] [blame] | 115 | cmocka_unit_test(linux_spi_init_and_shutdown_test_success), |
Anastasia Klimchuk | cffaac1 | 2021-04-21 07:58:30 +1000 | [diff] [blame] | 116 | }; |
| 117 | ret |= cmocka_run_group_tests_name("init_shutdown.c tests", init_shutdown_tests, NULL, NULL); |
| 118 | |
Edward O'Callaghan | 46f2d4e | 2020-05-20 20:10:20 +1000 | [diff] [blame] | 119 | return ret; |
| 120 | } |