diff options
author | Marat Dukhan <marat@fb.com> | 2017-08-09 17:00:32 -0700 |
---|---|---|
committer | Marat Dukhan <marat@fb.com> | 2017-08-09 17:00:38 -0700 |
commit | 079ccbd263a842e3d3d8266c01404cf49dd43475 (patch) | |
tree | f2fd074ad3bce7104621154546a24ab30a7bdf2f /src/linux/smallfile.c | |
parent | 5b36846430982b0d1d1a12fc80f7c695d7ab02bc (diff) | |
download | cpuinfo-079ccbd263a842e3d3d8266c01404cf49dd43475.tar.gz |
Mock whole filesystem in ARM tests
Diffstat (limited to 'src/linux/smallfile.c')
-rw-r--r-- | src/linux/smallfile.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/linux/smallfile.c b/src/linux/smallfile.c index 0056024..cc92146 100644 --- a/src/linux/smallfile.c +++ b/src/linux/smallfile.c @@ -9,6 +9,9 @@ #include <unistd.h> #include <fcntl.h> +#if CPUINFO_MOCK + #include <cpuinfo-mock.h> +#endif #include <linux/api.h> #include <log.h> @@ -36,7 +39,11 @@ bool cpuinfo_linux_parse_small_file(const char* filename, size_t buffer_size, cp cpuinfo_log_debug("parsing small file %s", filename); #endif +#if CPUINFO_MOCK + file = cpuinfo_mock_open(filename, O_RDONLY); +#else file = open(filename, O_RDONLY); +#endif if (file == -1) { cpuinfo_log_error("failed to open %s: %s", filename, strerror(errno)); goto cleanup; @@ -46,7 +53,11 @@ bool cpuinfo_linux_parse_small_file(const char* filename, size_t buffer_size, cp size_t buffer_position = 0; ssize_t bytes_read; do { +#if CPUINFO_MOCK + bytes_read = cpuinfo_mock_read(file, &buffer[buffer_position], buffer_size - buffer_position); +#else bytes_read = read(file, &buffer[buffer_position], buffer_size - buffer_position); +#endif if (bytes_read < 0) { cpuinfo_log_error("failed to read file %s at position %zu: %s", filename, buffer_position, strerror(errno)); goto cleanup; @@ -62,7 +73,11 @@ bool cpuinfo_linux_parse_small_file(const char* filename, size_t buffer_size, cp cleanup: if (file != -1) { +#if CPUINFO_MOCK + cpuinfo_mock_close(file); +#else close(file); +#endif file = -1; } return status; |