diff --git a/test/fuzz/fuzz_cmp_tool.c b/test/fuzz/fuzz_cmp_tool.c index 183d58a272a25e15abf1c9d8afe72c43868f8c30..0fab4999cde1249af7f19a45fb44695950d02748 100644 --- a/test/fuzz/fuzz_cmp_tool.c +++ b/test/fuzz/fuzz_cmp_tool.c @@ -59,7 +59,8 @@ static int gen_argv(FUZZ_dataProducer_t *producer, char **argv, const char *data /* Add optional arguments no the end so they have higher priority */ end = argc-1; - add_argument_with_file(argv, end--, "-o", "/tmp/fuzz-output-cmp_tool"); + /* TODO: How to clean up written stuff by the cmp_tool? */ + add_argument_with_file(argv, end--, "-o", FUZZ_TMP_DIR "/fuzz-output-cmp_tool"); if (FUZZ_dataProducer_uint32Range(producer, 0, 1)) add_argument_with_file(argv, end--, "-d", data_file); if (FUZZ_dataProducer_uint32Range(producer, 0, 1)) diff --git a/test/fuzz/fuzz_data_producer.h b/test/fuzz/fuzz_data_producer.h index cdccd16a5a916ec8d1326a0be0fb7e378ba846f5..c5d4891a02f90315dc16122b08c51b396222b80e 100644 --- a/test/fuzz/fuzz_data_producer.h +++ b/test/fuzz/fuzz_data_producer.h @@ -29,13 +29,21 @@ #ifndef FUZZ_DATA_PRODUCER_H #define FUZZ_DATA_PRODUCER_H + #include <stddef.h> #include <stdint.h> -#include <stdio.h> #include <stdlib.h> #include <cmp_chunk.h> + +#ifdef __APPLE__ +# define FUZZ_TMP_DIR "/tmp" +#else +# define FUZZ_TMP_DIR "/dev/shm" +#endif + + /* Struct used for maintaining the state of the data */ typedef struct FUZZ_dataProducer_s FUZZ_dataProducer_t; @@ -47,14 +55,14 @@ void FUZZ_dataProducer_free(FUZZ_dataProducer_t *producer); /* Returns value between [min, max] */ uint32_t FUZZ_dataProducer_uint32Range(FUZZ_dataProducer_t *producer, uint32_t min, - uint32_t max); + uint32_t max); /* Returns a uint32 value */ uint32_t FUZZ_dataProducer_uint32(FUZZ_dataProducer_t *producer); /* Returns a signed value between [min, max] */ int32_t FUZZ_dataProducer_int32Range(FUZZ_dataProducer_t *producer, - int32_t min, int32_t max); + int32_t min, int32_t max); /* Provides compression parameters */ void FUZZ_dataProducer_cmp_par(FUZZ_dataProducer_t *producer, struct cmp_par *cmp_par); @@ -69,12 +77,16 @@ void FUZZ_dataProducer_rollBack(FUZZ_dataProducer_t *producer, size_t remainingB int FUZZ_dataProducer_empty(FUZZ_dataProducer_t *producer); /* Restricts the producer to only the last newSize bytes of data. -If newSize > current data size, nothing happens. Returns the number of bytes -the producer won't use anymore, after contracting. */ + * If newSize > current data size, nothing happens. Returns the number of bytes + * the producer won't use anymore, after contracting. + */ size_t FUZZ_dataProducer_contract(FUZZ_dataProducer_t *producer, size_t newSize); -/* Restricts the producer to use only the last X bytes of data, where X is - a random number in the interval [0, data_size]. Returns the size of the - remaining data the producer won't use anymore (the prefix). */ +/* Restricts the producer to use only the last X bytes of data, where X is a + * random number in the interval [0, data_size]. Returns the size of the + * remaining data the producer won't use anymore (the prefix). + */ size_t FUZZ_dataProducer_reserveDataPrefix(FUZZ_dataProducer_t *producer); + + #endif // FUZZ_DATA_PRODUCER_H diff --git a/test/fuzz/fuzz_helpers.c b/test/fuzz/fuzz_helpers.c index 7a150b6d584377c8144577b7b96bf3f711519ee9..55b6cdf5f89964be695b03d7c57b1ba1fc6249b1 100644 --- a/test/fuzz/fuzz_helpers.c +++ b/test/fuzz/fuzz_helpers.c @@ -30,6 +30,7 @@ #include <errno.h> #include "fuzz_helpers.h" +#include "fuzz_data_producer.h" void *FUZZ_malloc(size_t size) @@ -61,11 +62,7 @@ char *FUZZ_buf_to_file(const uint8_t *buf, size_t size) int fd, ret_close; size_t pos = 0; -#ifdef __APPLE__ - char *path_name = strdup("/tmp/fuzz-XXXXXX"); -#else - char *path_name = strdup("/dev/shm/fuzz-XXXXXX"); -#endif + char *path_name = strdup(FUZZ_TMP_DIR "/fuzz-XXXXXX"); FUZZ_ASSERT(path_name != NULL);