1# This file is part of the flashrom project. 2# 3# Copyright 2020 Google LLC 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; version 2 of the License. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13 14test_srcs = files( 15 'io_mock.c', 16 'tests.c', 17 'libusb_wraps.c', 18 'helpers.c', 19 'flashrom.c', 20 'spi25.c', 21 'lifecycle.c', 22 'layout.c', 23 'chip.c', 24 'chip_wp.c', 25 'selfcheck.c', 26 'io_real.c', 27) 28 29if not programmer.get('dummy').get('active') 30 test_srcs += programmer.get('dummy').get('srcs') 31endif 32 33foreach p_name, p_data : programmer 34 test_srcs += p_data.get('test_srcs') 35endforeach 36 37mocks = [ 38 '-Wl,--wrap=strdup', 39 '-Wl,--wrap=physunmap', 40 '-Wl,--wrap=physmap', 41 '-Wl,--wrap=pcidev_init', 42 '-Wl,--wrap=pcidev_readbar', 43 '-Wl,--wrap=spi_send_command', 44 '-Wl,--wrap=sio_write', 45 '-Wl,--wrap=sio_read', 46 '-Wl,--wrap=open', 47 '-Wl,--wrap=open64', 48 '-Wl,--wrap=__open64_2', 49 '-Wl,--wrap=ioctl', 50 '-Wl,--wrap=read', 51 '-Wl,--wrap=write', 52 '-Wl,--wrap=fopen', 53 '-Wl,--wrap=fopen64', 54 '-Wl,--wrap=fdopen', 55 '-Wl,--wrap=fwrite', 56 '-Wl,--wrap=fflush', 57 '-Wl,--wrap=stat', 58 '-Wl,--wrap=stat64', 59 '-Wl,--wrap=__xstat', 60 '-Wl,--wrap=__xstat64', 61 '-Wl,--wrap=fstat', 62 '-Wl,--wrap=fstat64', 63 '-Wl,--wrap=__fstat50', 64 '-Wl,--wrap=__fxstat', 65 '-Wl,--wrap=__fxstat64', 66 '-Wl,--wrap=fileno', 67 '-Wl,--wrap=fsync', 68 '-Wl,--wrap=fread', 69 '-Wl,--wrap=fgets', 70 '-Wl,--wrap=fprintf', 71 '-Wl,--wrap=fclose', 72 '-Wl,--wrap=feof', 73 '-Wl,--wrap=ferror', 74 '-Wl,--wrap=flock', 75 '-Wl,--wrap=ftruncate', 76 '-Wl,--wrap=clearerr', 77 '-Wl,--wrap=setvbuf', 78 '-Wl,--wrap=rget_io_perms', 79 '-Wl,--wrap=OUTB', 80 '-Wl,--wrap=INB', 81 '-Wl,--wrap=OUTW', 82 '-Wl,--wrap=INW', 83 '-Wl,--wrap=OUTL', 84 '-Wl,--wrap=INL', 85 '-Wl,--wrap=usb_dev_get_by_vid_pid_number', 86 '-Wl,--wrap=libusb_init', 87 '-Wl,--wrap=libusb_set_debug', 88 '-Wl,--wrap=libusb_set_option', 89 '-Wl,--wrap=libusb_open', 90 '-Wl,--wrap=libusb_set_auto_detach_kernel_driver', 91 '-Wl,--wrap=libusb_detach_kernel_driver', 92 '-Wl,--wrap=libusb_attach_kernel_driver', 93 '-Wl,--wrap=libusb_open_device_with_vid_pid', 94 '-Wl,--wrap=libusb_get_device', 95 '-Wl,--wrap=libusb_get_device_list', 96 '-Wl,--wrap=libusb_free_device_list', 97 '-Wl,--wrap=libusb_get_bus_number', 98 '-Wl,--wrap=libusb_get_device_address', 99 '-Wl,--wrap=libusb_get_device_descriptor', 100 '-Wl,--wrap=libusb_get_config_descriptor', 101 '-Wl,--wrap=libusb_free_config_descriptor', 102 '-Wl,--wrap=libusb_get_configuration', 103 '-Wl,--wrap=libusb_set_configuration', 104 '-Wl,--wrap=libusb_claim_interface', 105 '-Wl,--wrap=libusb_control_transfer', 106 '-Wl,--wrap=libusb_release_interface', 107 '-Wl,--wrap=libusb_ref_device', 108 '-Wl,--wrap=libusb_unref_device', 109 '-Wl,--wrap=libusb_close', 110 '-Wl,--wrap=libusb_alloc_transfer', 111 '-Wl,--wrap=libusb_submit_transfer', 112 '-Wl,--wrap=libusb_free_transfer', 113 '-Wl,--wrap=libusb_handle_events_timeout', 114 '-Wl,--wrap=libusb_exit', 115 '-Wl,--gc-sections', 116] 117 118threads_dep = dependency('threads') 119 120flashrom_tests = executable('flashrom_unit_tests', 121 test_srcs, 122 c_args : [ 123 cargs, 124 '-ffunction-sections', 125 '-fdata-sections', 126 '-U_FORTIFY_SOURCE', 127 ], 128 export_dynamic : true, 129 link_args : mocks + link_args, 130 dependencies : [cmocka_dep, flashrom_test_dep, threads_dep], 131) 132test('cmocka test flashrom', flashrom_tests, timeout: 0) 133 134if get_option('llvm_cov').enabled() 135 run_target('llvm-cov-tests', command : ['../scripts/llvm-cov', flashrom_tests]) 136endif 137