diff --git a/.lcovrc b/.lcovrc new file mode 100644 index 0000000000000000000000000000000000000000..29a0562b495a2fa39ede342597651d4f373c7808 --- /dev/null +++ b/.lcovrc @@ -0,0 +1 @@ +lcov_excl_br_line = LCOV_EXCL_BR_LINE|cpu_to_be16|cpu_to_be32|cpu_to_be64|be16_to_cpu|be32_to_cpu|be64_to_cpu diff --git a/examples/example_cmp_icu.c b/examples/example_cmp_icu.c index ba704fcb2eeffcfb062082ab75be014766eaa8ce..f0d783e8523fc7e2177bcf81a57b1147a44a5600 100644 --- a/examples/example_cmp_icu.c +++ b/examples/example_cmp_icu.c @@ -39,7 +39,7 @@ #define MODEL_COUNTER 1 -int demo_icu_compression(void) +static int demo_icu_compression(void) { struct cmp_cfg example_cfg; struct cmp_entity *cmp_entity = NULL; diff --git a/examples/example_cmp_rdcu.c b/examples/example_cmp_rdcu.c index 9bf81cea40f715b6f563496768618a2c2e1e039e..93c76dfa469604502d9cf8ff41b1f72d86b62f6c 100644 --- a/examples/example_cmp_rdcu.c +++ b/examples/example_cmp_rdcu.c @@ -23,6 +23,7 @@ #include <cmp_rdcu.h> #include <cmp_entity.h> +#include <leon_inttypes.h> #define MAX_PAYLOAD_SIZE 4096 #define DATA_SAMPLES 6 /* number of 16 bit samples to compress */ @@ -148,7 +149,7 @@ int demo_rdcu_compression(void) /* get the size of the compression entity */ cmp_ent_size = cmp_ent_build(NULL, CMP_ASW_VERSION_ID, START_TIME, END_TIME, MODEL_ID, MODEL_COUNTER, - &example_cfg, example_info.cmp_size); + &example_cfg, (int)example_info.cmp_size); if (!cmp_ent_size) { printf("Error occurred during cmp_ent_build()\n"); return -1; @@ -164,7 +165,7 @@ int demo_rdcu_compression(void) /* now let us build the compression entity */ cmp_ent_size = cmp_ent_build(cmp_ent, CMP_ASW_VERSION_ID, START_TIME, END_TIME, MODEL_ID, MODEL_COUNTER, - &example_cfg, example_info.cmp_size); + &example_cfg, (int)example_info.cmp_size); if (!cmp_ent_size) { printf("Error occurred during cmp_ent_build()\n"); return -1; @@ -186,7 +187,7 @@ int demo_rdcu_compression(void) } s = cmp_ent_get_size(cmp_ent); - printf("\n\nHere's the compressed data including the header (size %lu):\n" + printf("\n\nHere's the compressed data including the header (size %"PRIu32"):\n" "============================================================\n", s); for (i = 0; i < s; i++) { uint8_t *p = (uint8_t *)cmp_ent; diff --git a/lib/common/byteorder.h b/lib/common/byteorder.h index 634e184324ffbac06efd89a41d7f563bbd51b6c5..fc5ff3512c3be848dcb709c893321720cdf15e7e 100644 --- a/lib/common/byteorder.h +++ b/lib/common/byteorder.h @@ -56,7 +56,7 @@ #ifndef __BIG_ENDIAN # if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) # define __BIG_ENDIAN 4321 -# elif defined(__clang__) && __BIG_ENDIAN__ +# elif defined(__clang__) && defined(__BIG_ENDIAN__) # define __BIG_ENDIAN 4321 # elif defined(__sparc__) # define __BIG_ENDIAN 4321 @@ -66,7 +66,7 @@ #ifndef __LITTLE_ENDIAN # if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) # define __LITTLE_ENDIAN 1234 -# elif defined(__clang__) && __LITTLE_ENDIAN__ +# elif defined(__clang__) & defined(__LITTLE_ENDIAN__) # define __LITTLE_ENDIAN 1234 # elif defined(_MSC_VER) && (_M_AMD64 || _M_IX86) # define __LITTLE_ENDIAN 1234 diff --git a/lib/common/cmp_data_types.c b/lib/common/cmp_data_types.c index f548702fb487d89d68b8f3dae91c63c724afaa02..11ebe418ddaea18a3643e4f2039ec22360eed06b 100644 --- a/lib/common/cmp_data_types.c +++ b/lib/common/cmp_data_types.c @@ -26,6 +26,12 @@ #include "cmp_data_types.h" +#ifdef __BIG_ENDIAN +# define CMP_IS_BIG_ENDIAN 1 +#else +# define CMP_IS_BIG_ENDIAN 0 +#endif + /** * @brief get the collection timestamp from the collection header * @@ -885,7 +891,9 @@ int be_to_cpu_data_type(void *data, uint32_t data_size_byte, enum cmp_data_type } samples = data_size_byte / sample_size; -#ifdef __LITTLE_ENDIAN + if (CMP_IS_BIG_ENDIAN) + return 0; + switch (data_type) { case DATA_TYPE_IMAGETTE: case DATA_TYPE_IMAGETTE_ADAPTIVE: @@ -949,7 +957,6 @@ int be_to_cpu_data_type(void *data, uint32_t data_size_byte, enum cmp_data_type return -1; /* LCOV_EXCL_STOP */ } -#endif /* __LITTLE_ENDIAN */ return 0; } diff --git a/lib/common/cmp_debug.c b/lib/common/cmp_debug.c index db1645d40c8a4bef8d44cb91c91949fa33dded0f..7d45515154fcd15a6e86d2d641159dfc30f94915 100644 --- a/lib/common/cmp_debug.c +++ b/lib/common/cmp_debug.c @@ -16,6 +16,7 @@ * @brief compression/decompression debugging printing functions */ +#if (DEBUGLEVEL > 0) #ifndef ICU_ASW # include <stdio.h> @@ -85,3 +86,5 @@ void cmp_debug_print_impl(const char *fmt, ...) cmp_debug_puts(print_buffer); } + +#endif /* (DEBUGLEVEL > 0) */ diff --git a/lib/common/cmp_debug.h b/lib/common/cmp_debug.h index df599117bf614d4f09b377e0e8d74c84db94d52d..5d950932b7b8f40f6ac9715be5decd96937ccd01 100644 --- a/lib/common/cmp_debug.h +++ b/lib/common/cmp_debug.h @@ -23,19 +23,23 @@ /* DEBUGLEVEL should be externally defined, usually via the compiler command * line. Its value must be a numeric value. */ #ifndef DEBUGLEVEL -# define DEBUGLEVEL 0 +# ifdef DEBUG +# define DEBUGLEVEL 1 +# else +# define DEBUGLEVEL 0 +# endif #endif #define PRINT_BUFFER_SIZE 256 __extension__ -#if (defined(DEBUG) || DEBUGLEVEL > 0) +#if (DEBUGLEVEL > 0) # define debug_print(...) cmp_debug_print_impl(__VA_ARGS__) +void cmp_debug_print_impl(const char *fmt, ...); #else # define debug_print(...) do {} while (0) #endif -void cmp_debug_print_impl(const char *fmt, ...); #endif /* CMP_DEBUG_H */ diff --git a/lib/common/cmp_entity.c b/lib/common/cmp_entity.c index 73f91679fff990a72c93aa0b34da6c586c8ffac3..056b41fa49337c4ba758bf929bf0f28daebe621c 100644 --- a/lib/common/cmp_entity.c +++ b/lib/common/cmp_entity.c @@ -2174,11 +2174,13 @@ static time_t my_timegm(struct tm *tm) uint64_t cmp_ent_create_timestamp(const struct timespec *ts) { struct tm epoch_date = PLATO_EPOCH_DATE; - struct timespec epoch = { my_timegm(&epoch_date), 0 }; + struct timespec epoch = {0, 0 }; struct timespec now = { 0, 0 }; double seconds; uint64_t coarse, fine; + epoch.tv_sec = my_timegm(&epoch_date); + /* LCOV_EXCL_START */ /* if time cannot be represented as a time_t object epoch.tv_sec = -1 */ if (epoch.tv_sec == -1) diff --git a/lib/common/compiler.h b/lib/common/compiler.h index dc6e7a90ab577f01f4918d82576bba0144a54ffa..5128c0ccf3fc39790f87f43c7a842701ebe9a04d 100644 --- a/lib/common/compiler.h +++ b/lib/common/compiler.h @@ -77,7 +77,7 @@ ((b) > maximum_unsigned_value_of_type(a) - (a)) -#define __get_unaligned_t(type, ptr) __extension__ ({ \ +#define __get_unaligned_t(type, ptr) __extension__ ({ \ const struct { type x; } __attribute__((packed)) *__pptr = (__typeof__(__pptr))(ptr); \ __pptr->x; \ }) @@ -131,7 +131,6 @@ #endif - /** * @brief mark a variable as potentially unused to suppress compiler warnings. * diff --git a/lib/common/vsnprintf.c b/lib/common/vsnprintf.c index ef5cc57887f13a8a4ae200ea77043c11992efd6d..eb3894b478291f90ee230c637c60ab1972f573f4 100644 --- a/lib/common/vsnprintf.c +++ b/lib/common/vsnprintf.c @@ -27,6 +27,8 @@ * reentrant! */ +#if (DEBUGLEVEL > 0) + #include <stdbool.h> #include <stdint.h> #include <stddef.h> @@ -883,3 +885,4 @@ int my_vsnprintf(char* buffer, size_t count, const char* format, va_list va) return _vsnprintf(_out_buffer, buffer, count, format, va); } +#endif /* (DEBUGLEVEL > 0) */ diff --git a/lib/common/vsnprintf.h b/lib/common/vsnprintf.h index 8b04ab66f6073027359eb37053a0184a53e5b079..8afed651ce694c23b995daef1c3f354b80bb999b 100644 --- a/lib/common/vsnprintf.h +++ b/lib/common/vsnprintf.h @@ -20,6 +20,8 @@ #ifndef VSNPRINTF_H #define VSNPRINTF_H +#if (DEBUGLEVEL > 0) int my_vsnprintf(char* buffer, size_t count, const char* format, va_list va); +#endif #endif /* VSNPRINTF_H */ diff --git a/lib/decompress/cmp_max_used_bits_list.c b/lib/decompress/cmp_max_used_bits_list.c index f4844ffc58da55b555523afe7281315fd0ae9491..31c14b2b92cbc76304b1ab4d52f23b968eadc4b3 100644 --- a/lib/decompress/cmp_max_used_bits_list.c +++ b/lib/decompress/cmp_max_used_bits_list.c @@ -24,6 +24,7 @@ #include "../common/list.h" #include "../common/cmp_max_used_bits.h" +#include "cmp_max_used_bits_list.h" struct list_item { diff --git a/lib/decompress/decmp.c b/lib/decompress/decmp.c index e21235043179574e2846210806fee839ba7f486e..6d7cf065bc886964e44d13c6453def18603aecf3 100644 --- a/lib/decompress/decmp.c +++ b/lib/decompress/decmp.c @@ -33,6 +33,7 @@ #include "read_bitstream.h" #include "cmp_max_used_bits_list.h" +#include "../decmp.h" #include "../common/cmp_debug.h" #include "../common/cmp_support.h" #include "../common/cmp_entity.h" @@ -400,7 +401,7 @@ static void configure_decoder_setup(struct decoder_setup *setup, struct bit_deco * @returns pointer to the collection data; NULL if col is NULL */ -void *get_collection_data(void *col) +static void *get_collection_data(void *col) { if (col) col = (uint8_t *)col + COLLECTION_HDR_SIZE; diff --git a/lib/icu_compress/cmp_icu.c b/lib/icu_compress/cmp_icu.c index 36837c6441de21c2a4daf69c1ea411be7bff27e3..22919272f034cc8d64da0a9a7dc98a8d7d8deb71 100644 --- a/lib/icu_compress/cmp_icu.c +++ b/lib/icu_compress/cmp_icu.c @@ -109,7 +109,7 @@ enum chunk_type { CHUNK_TYPE_SAT_IMAGETTE, CHUNK_TYPE_OFFSET_BACKGROUND, /* N-CAM */ CHUNK_TYPE_SMEARING, - CHUNK_TYPE_F_CHAIN, + CHUNK_TYPE_F_CHAIN }; diff --git a/lib/rdcu_compress/cmp_rdcu.c b/lib/rdcu_compress/cmp_rdcu.c index 7feeda49f3ef0f971414d476c49dec5f2e5887e2..457d975249341f81c2c8b50436ad2620ae11b881 100644 --- a/lib/rdcu_compress/cmp_rdcu.c +++ b/lib/rdcu_compress/cmp_rdcu.c @@ -31,9 +31,11 @@ #include "../common/cmp_debug.h" #include "../common/cmp_support.h" +#include "cmp_rdcu_testing.h" #include "cmp_rdcu_cfg.h" #include "rdcu_ctrl.h" #include "rdcu_rmap.h" +#include "../cmp_rdcu.h" #define RDCU_INTR_SIG_ENA 1 /* RDCU interrupt signal enabled */ diff --git a/lib/rdcu_compress/cmp_rdcu_testing.h b/lib/rdcu_compress/cmp_rdcu_testing.h new file mode 100644 index 0000000000000000000000000000000000000000..56f24094dc11da394f4911d65574f62e33463e27 --- /dev/null +++ b/lib/rdcu_compress/cmp_rdcu_testing.h @@ -0,0 +1,30 @@ +/** + * @file cmp_rdcu_testing.h + * @author Dominik Loidolt (dominik.loidolt@univie.ac.at) + * @date 2024 + * + * @copyright GPLv2 + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * @brief function to test RDCU compression + * @warning not indented for production use; only for testing + */ + +#ifndef CMP_RDCU_TESTING_H +#define CMP_RDCU_TESTING_H + +#include "../common/cmp_support.h" + +int rdcu_start_compression(void); +int rdcu_inject_edac_error(const struct cmp_cfg *cfg, uint32_t addr); +int rdcu_compress_data_parallel(const struct cmp_cfg *cfg, + const struct cmp_info *last_info); + +#endif /* CMP_RDCU_TESTING_H */ diff --git a/lib/rdcu_compress/rmap.c b/lib/rdcu_compress/rmap.c index 2361329552aabc07674e600a554e38ba6ad8b349..1ef7811c43fab9a34ea8d6f9748d202548aa6de4 100644 --- a/lib/rdcu_compress/rmap.c +++ b/lib/rdcu_compress/rmap.c @@ -571,7 +571,7 @@ struct rmap_pkt *rmap_pkt_from_buffer(uint8_t *buf, uint32_t len) size_t pkt_size = RMAP_DATA_START + n + pkt->data_len + 1; /* +1 for data CRC */ if (len < pkt_size) { - debug_print("buffer len is smaller than the contained RMAP packet; buf len: %" PRIu32 " bytes vs RMAP: %zu bytes needed", + debug_print("buffer len is smaller than the contained RMAP packet; buf len: %" PRIu32 " bytes vs RMAP: %lu bytes needed", len, pkt_size); goto error; } diff --git a/meson.build b/meson.build index 86680eeccc3ce1037253abd65d9568a1d4183c1b..7f7954389c057dd32fe8f0b43755a7b254f69867 100644 --- a/meson.build +++ b/meson.build @@ -1,10 +1,10 @@ project('cmp_tool', 'c', - version : '0.12-b3', - meson_version : '>= 0.56', + version : '0.12-b4', + meson_version : '>= 0.63', license : 'GPL-2.0', default_options : [ 'warning_level=3', - 'c_std=gnu99' + 'c_std=gnu89' ] ) @@ -19,6 +19,7 @@ feature_argument_input_mode = get_option('argument_input_mode') # Compiler flags +add_global_arguments('-Wno-long-long', language : 'c') cc_flags = ['-DDEBUGLEVEL=@0@'.format(debug_level)] if use_debug debug_flags = [ @@ -36,7 +37,7 @@ if use_debug '-Wfloat-equal', '-Wwrite-strings', '-Wold-style-definition', - '-Waggregate-return', +# '-Waggregate-return', '-Wmissing-declarations', '-Wmissing-include-dirs' ] diff --git a/programs/cmp_io.c b/programs/cmp_io.c index fd1100812924e37cca53084274b10e7bb53cdd3f..da755f7c56845ed9d374494ab297a1f0f07ad2d2 100644 --- a/programs/cmp_io.c +++ b/programs/cmp_io.c @@ -1201,7 +1201,7 @@ static __inline ssize_t str2uint8_arr(const char *str, uint8_t *data, uint32_t b if (!data) /* finished counting the sample */ break; - fprintf(stderr, "%s: %s: Error: The files do not contain enough data. Expected: 0x%x, has 0x%zx.\n", + fprintf(stderr, "%s: %s: Error: The files do not contain enough data. Expected: 0x%x, has 0x%lx.\n", PROGRAM_NAME, file_name, buf_size, i); return -1; } @@ -1459,7 +1459,7 @@ ssize_t read_file_cmp_entity(const char *file_name, struct cmp_entity *ent, return -1; } if (size != (ssize_t)cmp_ent_get_size(ent)) { - fprintf(stderr, "%s: %s: The size of the compression entity set in the header of the compression entity is not the same size as the read-in file has. Expected: 0x%x, has 0x%zx.\n", + fprintf(stderr, "%s: %s: The size of the compression entity set in the header of the compression entity is not the same size as the read-in file has. Expected: 0x%x, has 0x%lx.\n", PROGRAM_NAME, file_name, cmp_ent_get_size(ent), (size_t)size); return -1; } diff --git a/programs/cmp_tool.c b/programs/cmp_tool.c index 3dd5a9a7de253bc4ff6d1eae22f1888509a6d121..8f77e6293c7baac45f10762435a766902256a36b 100644 --- a/programs/cmp_tool.c +++ b/programs/cmp_tool.c @@ -76,7 +76,7 @@ enum { LAST_INFO, NO_HEADER, MODEL_ID, - MODEL_COUTER, + MODEL_COUTER }; static const struct option long_options[] = { diff --git a/programs/meson.build b/programs/meson.build index ad9de48a3134ba7fb5b529796e34b9a835d49500..4cb183c5ed554dd1e0d3a8ee2ff492275c359de1 100644 --- a/programs/meson.build +++ b/programs/meson.build @@ -24,5 +24,5 @@ cmp_tool_exe = executable('cmp_tool', sources : cmp_tool_src, include_directories : incdir, link_with : cmp_lib, - install : 'true' + install : true ) diff --git a/programs/rdcu_pkt_to_file.c b/programs/rdcu_pkt_to_file.c index 28df657cf3df16d4d7842f141b3b404838263437..bc8734f6895e5680246488a2fd78ff4e2ca32c2a 100644 --- a/programs/rdcu_pkt_to_file.c +++ b/programs/rdcu_pkt_to_file.c @@ -34,9 +34,7 @@ #include <rdcu_rmap.h> #include <rdcu_ctrl.h> #include <rdcu_cmd.h> - - -int rdcu_compress_data_parallel(const struct cmp_cfg *cfg, const struct cmp_info *last_info); +#include <cmp_rdcu_testing.h> /* Name of directory were the RMAP packages are stored */ diff --git a/subprojects/packagefiles/pcg-c-basic-Port-to-C89.patch b/subprojects/packagefiles/pcg-c-basic-Port-to-C89.patch new file mode 100644 index 0000000000000000000000000000000000000000..e74f41a5041846f15a988bbf403fe55713b1a878 --- /dev/null +++ b/subprojects/packagefiles/pcg-c-basic-Port-to-C89.patch @@ -0,0 +1,206 @@ +From c5b6186b22b939f131c8f098fce3e4338f780c58 Mon Sep 17 00:00:00 2001 +From: Dominik Loidolt <dominik.loidolt@univie.ac.at> +Date: Fri, 15 Mar 2024 18:21:32 +0100 +Subject: [PATCH] Port to C89 + +--- + pcg_basic.c | 78 ++++++++++++++++++++++++++++++----------------------- + pcg_basic.h | 41 +++++++++++++++------------- + 2 files changed, 66 insertions(+), 53 deletions(-) + +diff --git a/pcg_basic.c b/pcg_basic.c +index 8c2fd0d..79f1d0a 100644 +--- a/pcg_basic.c ++++ b/pcg_basic.c +@@ -30,14 +30,16 @@ + + #include "pcg_basic.h" + +-// state for global RNGs ++/* state for global RNGs */ + + static pcg32_random_t pcg32_global = PCG32_INITIALIZER; + +-// pcg32_srandom(initstate, initseq) +-// pcg32_srandom_r(rng, initstate, initseq): +-// Seed the rng. Specified in two parts, state initializer and a +-// sequence selection constant (a.k.a. stream id) ++/* ++ * pcg32_srandom(initstate, initseq) ++ * pcg32_srandom_r(rng, initstate, initseq): ++ * Seed the rng. Specified in two parts, state initializer and a ++ * sequence selection constant (a.k.a. stream id) ++ */ + + void pcg32_srandom_r(pcg32_random_t* rng, uint64_t initstate, uint64_t initseq) + { +@@ -53,54 +55,62 @@ void pcg32_srandom(uint64_t seed, uint64_t seq) + pcg32_srandom_r(&pcg32_global, seed, seq); + } + +-// pcg32_random() +-// pcg32_random_r(rng) +-// Generate a uniformly distributed 32-bit random number ++/* ++ * pcg32_random(void) ++ * pcg32_random_r(rng) ++ * Generate a uniformly distributed 32-bit random number ++ */ + + uint32_t pcg32_random_r(pcg32_random_t* rng) + { + uint64_t oldstate = rng->state; +- rng->state = oldstate * 6364136223846793005ULL + rng->inc; +- uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u; ++ uint32_t xorshifted = (uint32_t)(((oldstate >> 18u) ^ oldstate) >> 27u); + uint32_t rot = oldstate >> 59u; ++ ++ rng->state = oldstate * 6364136223846793005ULL + rng->inc; + return (xorshifted >> rot) | (xorshifted << ((-rot) & 31)); + } + +-uint32_t pcg32_random() ++uint32_t pcg32_random(void) + { + return pcg32_random_r(&pcg32_global); + } + + +-// pcg32_boundedrand(bound): +-// pcg32_boundedrand_r(rng, bound): +-// Generate a uniformly distributed number, r, where 0 <= r < bound ++/* ++ * pcg32_boundedrand(bound): ++ * pcg32_boundedrand_r(rng, bound): ++ * Generate a uniformly distributed number, r, where 0 <= r < bound ++ */ + + uint32_t pcg32_boundedrand_r(pcg32_random_t* rng, uint32_t bound) + { +- // To avoid bias, we need to make the range of the RNG a multiple of +- // bound, which we do by dropping output less than a threshold. +- // A naive scheme to calculate the threshold would be to do +- // +- // uint32_t threshold = 0x100000000ull % bound; +- // +- // but 64-bit div/mod is slower than 32-bit div/mod (especially on +- // 32-bit platforms). In essence, we do +- // +- // uint32_t threshold = (0x100000000ull-bound) % bound; +- // +- // because this version will calculate the same modulus, but the LHS +- // value is less than 2^32. ++ /* To avoid bias, we need to make the range of the RNG a multiple of ++ * bound, which we do by dropping output less than a threshold. ++ * A naive scheme to calculate the threshold would be to do ++ * ++ * uint32_t threshold = 0x100000000ull % bound; ++ * ++ * but 64-bit div/mod is slower than 32-bit div/mod (especially on ++ * 32-bit platforms). In essence, we do ++ * ++ * uint32_t threshold = (0x100000000ull-bound) % bound; ++ * ++ * because this version will calculate the same modulus, but the LHS ++ * value is less than 2^32. ++ */ + + uint32_t threshold = -bound % bound; + +- // Uniformity guarantees that this loop will terminate. In practice, it +- // should usually terminate quickly; on average (assuming all bounds are +- // equally likely), 82.25% of the time, we can expect it to require just +- // one iteration. In the worst case, someone passes a bound of 2^31 + 1 +- // (i.e., 2147483649), which invalidates almost 50% of the range. In +- // practice, bounds are typically small and only a tiny amount of the range +- // is eliminated. ++ /* ++ * Uniformity guarantees that this loop will terminate. In practice, it ++ * should usually terminate quickly; on average (assuming all bounds are ++ * equally likely), 82.25% of the time, we can expect it to require just ++ * one iteration. In the worst case, someone passes a bound of 2^31 + 1 ++ * (i.e., 2147483649), which invalidates almost 50% of the range. In ++ * practice, bounds are typically small and only a tiny amount of the range ++ * is eliminated. ++ */ + for (;;) { + uint32_t r = pcg32_random_r(rng); + if (r >= threshold) +diff --git a/pcg_basic.h b/pcg_basic.h +index e2b526a..63ae2db 100644 +--- a/pcg_basic.h ++++ b/pcg_basic.h +@@ -31,48 +31,51 @@ + #ifndef PCG_BASIC_H_INCLUDED + #define PCG_BASIC_H_INCLUDED 1 + +-#include <inttypes.h> ++#include <stdint.h> + +-#if __cplusplus ++#ifdef __cplusplus + extern "C" { + #endif + +-struct pcg_state_setseq_64 { // Internals are *Private*. +- uint64_t state; // RNG state. All values are possible. +- uint64_t inc; // Controls which RNG sequence (stream) is +- // selected. Must *always* be odd. ++struct pcg_state_setseq_64 { /* Internals are *Private*. */ ++ uint64_t state; /* RNG state. All values are possible. */ ++ uint64_t inc; /* Controls which RNG sequence (stream) is */ ++ /* selected. Must *always* be odd. */ + }; + typedef struct pcg_state_setseq_64 pcg32_random_t; + +-// If you *must* statically initialize it, here's one. ++/* If you *must* statically initialize it, here's one. */ + + #define PCG32_INITIALIZER { 0x853c49e6748fea9bULL, 0xda3e39cb94b95bdbULL } + +-// pcg32_srandom(initstate, initseq) +-// pcg32_srandom_r(rng, initstate, initseq): +-// Seed the rng. Specified in two parts, state initializer and a +-// sequence selection constant (a.k.a. stream id) ++/* pcg32_srandom(initstate, initseq) ++ * pcg32_srandom_r(rng, initstate, initseq): ++ * Seed the rng. Specified in two parts, state initializer and a ++ * sequence selection constant (a.k.a. stream id) ++ */ + + void pcg32_srandom(uint64_t initstate, uint64_t initseq); + void pcg32_srandom_r(pcg32_random_t* rng, uint64_t initstate, + uint64_t initseq); + +-// pcg32_random() +-// pcg32_random_r(rng) +-// Generate a uniformly distributed 32-bit random number ++/* pcg32_random() ++ * pcg32_random_r(rng) ++ * Generate a uniformly distributed 32-bit random number ++ */ + + uint32_t pcg32_random(void); + uint32_t pcg32_random_r(pcg32_random_t* rng); + +-// pcg32_boundedrand(bound): +-// pcg32_boundedrand_r(rng, bound): +-// Generate a uniformly distributed number, r, where 0 <= r < bound ++/* pcg32_boundedrand(bound): ++ * pcg32_boundedrand_r(rng, bound): ++ * Generate a uniformly distributed number, r, where 0 <= r < bound ++ */ + + uint32_t pcg32_boundedrand(uint32_t bound); + uint32_t pcg32_boundedrand_r(pcg32_random_t* rng, uint32_t bound); + +-#if __cplusplus ++#ifdef __cplusplus + } + #endif + +-#endif // PCG_BASIC_H_INCLUDED ++#endif /* PCG_BASIC_H_INCLUDED */ +-- +2.44.0 + diff --git a/subprojects/packagefiles/pcg-c-basic/meson.build b/subprojects/packagefiles/pcg-c-basic/meson.build index efe83ebf8cb6f7cbc98690e22ff87b575867e78a..9724a0ba382337ea8378ce335371285417e82d5b 100644 --- a/subprojects/packagefiles/pcg-c-basic/meson.build +++ b/subprojects/packagefiles/pcg-c-basic/meson.build @@ -1,13 +1,14 @@ project('pcg-c-basic', 'c', version: '0.9', - license: 'Apache 2.0', + license: 'Apache 2.0' ) inc = include_directories('.') libpcg_basic = static_library('pcg_basic', 'pcg_basic.c', include_directories : inc, - install : true) + install : true +) libpcg_basic_dep = declare_dependency(include_directories : inc, link_with : libpcg_basic) diff --git a/subprojects/pcg-c-basic.wrap b/subprojects/pcg-c-basic.wrap index 1b24864cc6df36a5e3e62b90f9ab21a579b516d0..f9a0140c093eee8e6b1051cc45bc049b436f32cd 100644 --- a/subprojects/pcg-c-basic.wrap +++ b/subprojects/pcg-c-basic.wrap @@ -4,3 +4,4 @@ source_url = https://www.pcg-random.org/downloads/pcg-c-basic-0.9.zip source_filename = pcg-c-basic-0.9.zip source_hash = 143f9cc0edc7e81064bde5ed6c5f16cbf7ca2f373d35543286f5fe4475a2eff1 patch_directory = pcg-c-basic +diff_files = pcg-c-basic-Port-to-C89.patch diff --git a/subprojects/unity.wrap b/subprojects/unity.wrap index 8cc488366197ec4f255d93fb4642367c88f5744b..29246ac476339b20e6f4abcece97ca3009978f67 100644 --- a/subprojects/unity.wrap +++ b/subprojects/unity.wrap @@ -1,8 +1,8 @@ [wrap-file] -directory = Unity-2.5.2 -source_url = https://github.com/ThrowTheSwitch/Unity/archive/refs/tags/v2.5.2.tar.gz -source_filename = Unity-2.5.2.tar.gz -source_hash = 3786de6c8f389be3894feae4f7d8680a02e70ed4dbcce36109c8f8646da2671a +directory = Unity-2.6.0 +source_url = https://github.com/ThrowTheSwitch/Unity/archive/refs/tags/v2.6.0.tar.gz +source_filename = Unity-2.6.0.tar.gz +source_hash = aa4c9fb1ae5fc5242f914c65f3557e817e40cb37f04a31e5ff76d1ab89dbf674 [provide] unity = unity_dep diff --git a/test/cmp_data_types/meson.build b/test/cmp_data_types/meson.build index 17ff50e1f5752be2f639282aeb7b5a7212a74779..d84e4b67c1aa5ce70439be34e96624f1a19b70af 100644 --- a/test/cmp_data_types/meson.build +++ b/test/cmp_data_types/meson.build @@ -1,12 +1 @@ -test_case = files('test_cmp_data_types.c') -test_runner = test_runner_generator.process(test_case) - -test_cmp_data_types = executable('test_cmp_data_types', - test_case, test_runner, - include_directories : incdir, - link_with : cmp_lib, - dependencies : unity_dep, - build_by_default : false -) - -test('Compression Data Types Unit Tests', test_cmp_data_types) +test_cases += [[files('test_cmp_data_types.c'), 'Compression Data Types Unit Tests']] diff --git a/test/cmp_decmp/meson.build b/test/cmp_decmp/meson.build index 33a6f47b6ec7aa61fc87df95bd3715f5ce52217a..7feff7a097ba02582c0adea950f088de74c2cb0d 100644 --- a/test/cmp_decmp/meson.build +++ b/test/cmp_decmp/meson.build @@ -1,12 +1 @@ -test_case = files('test_cmp_decmp.c') -test_runner = test_runner_generator.process(test_case) - -test_cmp_decmp = executable('test_cmp_decmp', - test_case, test_runner, - include_directories : incdir, - link_with : [cmp_lib, test_common_lib], - dependencies : unity_dep, - build_by_default : false -) - -test('Compression Decompression Unit Tests', test_cmp_decmp) +test_cases += [[files('test_cmp_decmp.c'), 'Compression Decompression Unit Tests']] diff --git a/test/cmp_entity/meson.build b/test/cmp_entity/meson.build index 98fedca8e8fc6f0963ee7adb98583e86cc6aa103..e12717160f08a4d50bdf680d7e76489a66f49f02 100644 --- a/test/cmp_entity/meson.build +++ b/test/cmp_entity/meson.build @@ -1,12 +1 @@ -test_case = files('test_cmp_entity.c') -test_runner = test_runner_generator.process(test_case) - -test_cmp_entity = executable('test_cmp_entity', - test_case, test_runner, - include_directories : incdir, - link_with : cmp_lib, - dependencies : unity_dep, - build_by_default : false -) - -test('Compression Entity Unit Tests', test_cmp_entity) +test_cases += [[files('test_cmp_entity.c'), 'Compression Entity Unit Tests']] diff --git a/test/cmp_icu/meson.build b/test/cmp_icu/meson.build index f92d5ee1ef58c281d453cc92869046d2f887c752..7bc5eefd60ec390ce65a2e47cc56c503f3d3f403 100644 --- a/test/cmp_icu/meson.build +++ b/test/cmp_icu/meson.build @@ -1,12 +1 @@ -test_case = files('test_cmp_icu.c') -test_runner = test_runner_generator.process(test_case) - -test_cmp_icu = executable('test_cmp_icu', - test_case, test_runner, - include_directories : incdir, - link_with : [cmp_lib, test_common_lib], - dependencies : unity_dep, - build_by_default : false -) - -test('cmp_icu Unit Tests', test_cmp_icu) +test_cases += [[files('test_cmp_icu.c'), 'cmp_icu Unit Tests']] diff --git a/test/cmp_max_used_bits/meson.build b/test/cmp_max_used_bits/meson.build index a7c001e95c2ac125169bfdad6c514cbd48d3cdbc..b863442cc615cdd233797020fc204b22638e2da3 100644 --- a/test/cmp_max_used_bits/meson.build +++ b/test/cmp_max_used_bits/meson.build @@ -1,12 +1 @@ -test_case = files('test_cmp_max_used_bits_list.c') -test_runner = test_runner_generator.process(test_case) - -test_cmp_max_used_bits_list = executable('test_cmp_max_used_bits_list', - test_case, test_runner, - include_directories : incdir, - link_with : cmp_lib, - dependencies : unity_dep, - build_by_default : false -) - -test('max_used_bits List Unit Tests', test_cmp_max_used_bits_list) +test_cases += [[files('test_cmp_max_used_bits_list.c'), 'max_used_bits List Unit Tests']] diff --git a/test/cmp_rdcu_cfg/meson.build b/test/cmp_rdcu_cfg/meson.build index 3d01fd0297b23c01ac0c08ee604daecca97e2b6c..7242590e7973b51cb4b9eb9b89f3ce3eb068a739 100644 --- a/test/cmp_rdcu_cfg/meson.build +++ b/test/cmp_rdcu_cfg/meson.build @@ -1,12 +1 @@ -test_case = files('test_cmp_rdcu_cfg.c') -test_runner = test_runner_generator.process(test_case) - -test_cmp_rdcu_cfg = executable('test_cmp_rdcu_cfg', - test_case, test_runner, - include_directories : incdir, - link_with : cmp_lib, - dependencies : unity_dep, - build_by_default : false -) - -test('Hardware Compressor Configuration Tests', test_cmp_rdcu_cfg) +test_cases += [[files('test_cmp_rdcu_cfg.c'), 'Hardware Compressor Configuration Tests']] diff --git a/test/decmp/meson.build b/test/decmp/meson.build index 4c7778a171aaf083705dadea4b7904fb168dea01..6e2d7d9c7c16287e57aa3625b2e92d29e1845a34 100644 --- a/test/decmp/meson.build +++ b/test/decmp/meson.build @@ -1,12 +1 @@ -test_case = files('test_decmp.c') -test_runner = test_runner_generator.process(test_case) - -test_decmp = executable('test_decmp', - test_case, test_runner, - include_directories : incdir, - link_with : cmp_lib, - dependencies : unity_dep, - build_by_default : false -) - -test('Decompression Unit Tests', test_decmp) +test_cases += [[files('test_decmp.c'), 'Decompression Unit Tests']] diff --git a/test/meson.build b/test/meson.build index 63da2db81129ecc31764b1bd5faf24b609fa0a2a..50cd3df99279bd31ebaa96faf7850374cfb25e92 100644 --- a/test/meson.build +++ b/test/meson.build @@ -33,8 +33,9 @@ subdir('tools') subdir('cmp_tool') unity_dep = dependency('unity', fallback : ['unity', 'unity_dep']) - subdir('test_common') + +test_cases = [] subdir('decmp') subdir('cmp_icu') subdir('cmp_decmp') @@ -42,3 +43,31 @@ subdir('cmp_data_types') subdir('cmp_entity') subdir('cmp_rdcu_cfg') subdir('cmp_max_used_bits') + + +test_args = '-Wno-missing-declarations' # The test runner generator does not generate header files +fs = import('fs') + +foreach test : test_cases + test_src = test[0] + test_description = test[1] + + test_name = fs.name(test_src).split('.')[0] + test_runner = test_runner_generator.process(test_src) + test_libs = [cmp_lib] + + if test_name == 'test_cmp_decmp' or test_name == 'test_cmp_icu' + test_libs += test_common_lib + endif + + test_exe = executable(test_name, + test_src, test_runner, + include_directories : incdir, + link_with : test_libs, + dependencies : unity_dep, + c_args : test_args, + build_by_default : false + ) + + test(test_description, test_exe) +endforeach diff --git a/test/test_common/test_common.c b/test/test_common/test_common.c index 4f90832be876c6d41c2f386d9911ff5b4034f606..7a1b25f222677da77c292e8a0ea96b85ac6f5bfb 100644 --- a/test/test_common/test_common.c +++ b/test/test_common/test_common.c @@ -4,6 +4,7 @@ #include <string.h> #include "pcg_basic.h" +#include "test_common.h" #include <unity.h> diff --git a/test/tools/generate_test_runner.rb b/test/tools/generate_test_runner.rb index 1c0ec3450435f7c8cf95219afd6f9226b7389a0f..50c93f533e45d5aced318fa4b34cf4f853015936 100755 --- a/test/tools/generate_test_runner.rb +++ b/test/tools/generate_test_runner.rb @@ -218,16 +218,16 @@ class UnityTestRunnerGenerator if @options[:defines] && !@options[:defines].empty? @options[:defines].each { |d| output.puts("#ifndef #{d}\n#define #{d}\n#endif /* #{d} */") } end - if @options[:header_file] && !@options[:header_file].empty? - output.puts("#include \"#{File.basename(@options[:header_file])}\"") - else - @options[:includes].flatten.uniq.compact.each do |inc| - output.puts("#include #{inc.include?('<') ? inc : "\"#{inc}\""}") - end - testfile_includes.each do |inc| - output.puts("#include #{inc.include?('<') ? inc : "\"#{inc}\""}") - end - end + # if @options[:header_file] && !@options[:header_file].empty? + # output.puts("#include \"#{File.basename(@options[:header_file])}\"") + # else + # @options[:includes].flatten.uniq.compact.each do |inc| + # output.puts("#include #{inc.include?('<') ? inc : "\"#{inc}\""}") + # end + # testfile_includes.each do |inc| + # output.puts("#include #{inc.include?('<') ? inc : "\"#{inc}\""}") + # end + # end mocks.each do |mock| output.puts("#include \"#{mock}\"") end @@ -243,13 +243,13 @@ class UnityTestRunnerGenerator def create_externs(output, tests, _mocks) output.puts("\n/*=======External Functions This Runner Calls=====*/") - output.puts("extern void #{@options[:setup_name]}(void);") - output.puts("extern void #{@options[:teardown_name]}(void);") - output.puts("\n#ifdef __cplusplus\nextern \"C\"\n{\n#endif") if @options[:externc] + # output.puts("extern void #{@options[:setup_name]}(void);") + # output.puts("extern void #{@options[:teardown_name]}(void);") + # output.puts("\n#ifdef __cplusplus\nextern \"C\"\n{\n#endif") if @options[:externc] tests.each do |test| output.puts("extern void #{test[:test]}(#{test[:call] || 'void'});") end - output.puts("#ifdef __cplusplus\n}\n#endif") if @options[:externc] + # output.puts("#ifdef __cplusplus\n}\n#endif") if @options[:externc] output.puts('') end @@ -324,7 +324,7 @@ class UnityTestRunnerGenerator def create_reset(output) output.puts("\n/*=======Test Reset Options=====*/") - output.puts("void #{@options[:test_reset_name]}(void);") + # output.puts("void #{@options[:test_reset_name]}(void);") output.puts("void #{@options[:test_reset_name]}(void)") output.puts('{') output.puts(" #{@options[:teardown_name]}();") @@ -333,7 +333,7 @@ class UnityTestRunnerGenerator output.puts(' CMock_Init();') output.puts(" #{@options[:setup_name]}();") output.puts('}') - output.puts("void #{@options[:test_verify_name]}(void);") + # output.puts("void #{@options[:test_verify_name]}(void);") output.puts("void #{@options[:test_verify_name]}(void)") output.puts('{') output.puts(' CMock_Verify();') @@ -342,8 +342,9 @@ class UnityTestRunnerGenerator def create_run_test(output) require 'erb' - template = ERB.new(File.read(File.join(__dir__, 'run_test.erb')), nil, '<>') - output.puts("\n" + template.result(binding)) + file = File.read(File.join(__dir__, 'run_test.erb')) + template = ERB.new(file, trim_mode: '<>') + output.puts("\n#{template.result(binding)}") end def create_args_wrappers(output, tests)