blob: 701770f4979c1cca1ebb95656330f93ea1ddab7b [file] [log] [blame]
Nikolai Artemiev702c58a2020-09-16 14:12:22 +10001/*
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'Callaghan46f2d4e2020-05-20 20:10:20 +100015
16#include <include/test.h>
17#include "tests.h"
18
19#include <stdio.h>
Anastasia Klimchuk98534e72021-04-23 15:47:03 +100020#include <stdint.h>
Edward O'Callaghan46f2d4e2020-05-20 20:10:20 +100021
22/* redefinitions/wrapping */
Anastasia Klimchukab9d1462021-04-19 14:47:35 +100023#define LOG_ME printf("%s is called\n", __func__)
24
Edward O'Callaghan46f2d4e2020-05-20 20:10:20 +100025void __wrap_physunmap(void *virt_addr, size_t len)
26{
Anastasia Klimchukab9d1462021-04-19 14:47:35 +100027 LOG_ME;
Edward O'Callaghan46f2d4e2020-05-20 20:10:20 +100028}
Anastasia Klimchukab9d1462021-04-19 14:47:35 +100029
Edward O'Callaghan46f2d4e2020-05-20 20:10:20 +100030void *__wrap_physmap(const char *descr, uintptr_t phys_addr, size_t len)
31{
Anastasia Klimchukab9d1462021-04-19 14:47:35 +100032 LOG_ME;
Edward O'Callaghan46f2d4e2020-05-20 20:10:20 +100033 return NULL;
34}
35
Anastasia Klimchuk98534e72021-04-23 15:47:03 +100036void __wrap_sio_write(uint16_t port, uint8_t reg, uint8_t data)
37{
38 LOG_ME;
39}
40
41uint8_t __wrap_sio_read(uint16_t port, uint8_t reg)
42{
43 LOG_ME;
44 return (uint8_t)mock();
45}
46
47int __wrap_open(const char *pathname, int flags)
48{
49 LOG_ME;
50 return 2021;
51}
52
53int __wrap_open64(const char *pathname, int flags)
54{
55 LOG_ME;
56 return 2021;
57}
58
59int __wrap_ioctl(int fd, unsigned long int request, ...)
60{
61 LOG_ME;
62 return 2021;
63}
64
65FILE *__wrap_fopen(const char *pathname, const char *mode)
66{
67 LOG_ME;
68 return NULL;
69}
70
71FILE *__wrap_fopen64(const char *pathname, const char *mode)
72{
73 LOG_ME;
74 return NULL;
75}
76
Edward O'Callaghan46f2d4e2020-05-20 20:10:20 +100077int main(void)
78{
79 int ret = 0;
80
Anastasia Klimchukab9d1462021-04-19 14:47:35 +100081 cmocka_set_message_output(CM_OUTPUT_STDOUT);
82
Edward O'Callaghan3cc70c22020-05-22 18:42:11 +100083 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'Callaghan629b8f02020-05-22 16:46:52 +100094 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'Callaghan41f48c72020-05-22 16:46:26 +100099 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'Callaghan76d24452020-05-22 19:09:49 +1000109 cmocka_unit_test(probe_spi_st95_test_success), /* spi95.c */
Edward O'Callaghan41f48c72020-05-22 16:46:26 +1000110 };
111 ret |= cmocka_run_group_tests_name("spi25.c tests", spi25_tests, NULL, NULL);
112
Anastasia Klimchukcffaac12021-04-21 07:58:30 +1000113 const struct CMUnitTest init_shutdown_tests[] = {
114 cmocka_unit_test(dummy_init_and_shutdown_test_success),
Anastasia Klimchuk98534e72021-04-23 15:47:03 +1000115 cmocka_unit_test(linux_spi_init_and_shutdown_test_success),
Anastasia Klimchukcffaac12021-04-21 07:58:30 +1000116 };
117 ret |= cmocka_run_group_tests_name("init_shutdown.c tests", init_shutdown_tests, NULL, NULL);
118
Edward O'Callaghan46f2d4e2020-05-20 20:10:20 +1000119 return ret;
120}