Skip to content
Snippets Groups Projects
Commit a9845e42 authored by Dominik Loidolt's avatar Dominik Loidolt
Browse files

Merge branch 'debug_print' into 'master'

Updated debug_print(): Enhanced Adaptability for Various Environments

See merge request !28
parents 22415ff7 4811e45b
No related branches found
No related tags found
1 merge request!28Updated debug_print(): Enhanced Adaptability for Various Environments
Showing
with 1756 additions and 776 deletions
......@@ -53,16 +53,30 @@
#undef __LITTLE_ENDIAN
#endif
#if defined(__sparc__)
#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__
# define __BIG_ENDIAN 4321
# elif defined(__sparc__)
# define __BIG_ENDIAN 4321
# endif
#endif
#if defined(__i386__) || defined(__x86_64__)
#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__
# define __LITTLE_ENDIAN 1234
# elif defined(_MSC_VER) && (_M_AMD64 || _M_IX86)
# define __LITTLE_ENDIAN 1234
# elif defined(__i386__) || defined(__x86_64__)
# define __LITTLE_ENDIAN 1234
# endif
#endif
#if defined(__BIG_ENDIAN) == defined(__LITTLE_ENDIAN)
#error "Unknown byte order!"
#endif
......
......@@ -885,7 +885,7 @@ int be_to_cpu_data_type(void *data, uint32_t data_size_byte, enum cmp_data_type
}
samples = data_size_byte / sample_size;
#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#ifdef __LITTLE_ENDIAN
switch (data_type) {
case DATA_TYPE_IMAGETTE:
case DATA_TYPE_IMAGETTE_ADAPTIVE:
......@@ -949,7 +949,7 @@ int be_to_cpu_data_type(void *data, uint32_t data_size_byte, enum cmp_data_type
return -1;
/* LCOV_EXCL_STOP */
}
#endif /*__BYTE_ORDER__ */
#endif /* __LITTLE_ENDIAN */
return 0;
}
......
/**
* @file cmp_debug.c
* @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 compression/decompression debugging printing functions
*/
#ifndef ICU_ASW
# include <stdio.h>
#endif
#include <string.h>
#include <stdarg.h>
#include "cmp_debug.h"
#include "compiler.h"
#include "vsnprintf.h"
/**
* @brief outputs a debug string
*
* This function outputs a string for debugging purposes
*
* @param str The string to output
*/
static void cmp_debug_puts(const char *str)
{
#ifdef ICU_ASW
/* XXX adapt it to your needs */
/* asw_puts(str); */
(void)str;
#else
fputs(str, stderr);
fputs("\n", stderr);
#endif
}
/**
* @brief implements debug printing
*
* This function formats a string and prints it for debugging. It uses a static
* buffer to format the string
*
* @param fmt pointer to a null-terminated byte string specifying how to
* interpret the data
* @param ... arguments specifying data to print
*/
void cmp_debug_print_impl(const char *fmt, ...)
{
static char print_buffer[PRINT_BUFFER_SIZE];
int len;
va_list args;
va_start(args, fmt);
len = my_vsnprintf(print_buffer, sizeof(print_buffer)-1, fmt, args);
va_end(args);
if (len < 0) {
const char str[] = "my_snprintf is broken";
compile_time_assert(sizeof(str) <= sizeof(print_buffer), CMP_DEBUG_PRINT_BUFFER_SIZE_TO_SMALL);
memcpy(print_buffer, str, sizeof(str));
}
if ((size_t)len >= sizeof(print_buffer)-1) {
const char str[] = "cmp_debug print_buffer too small";
compile_time_assert(sizeof(str) <= sizeof(print_buffer), CMP_DEBUG_PRINT_BUFFER_SIZE_TO_SMALL);
memcpy(print_buffer, str, sizeof(str));
}
cmp_debug_puts(print_buffer);
}
......@@ -13,7 +13,7 @@
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* @brief compression/decompression debugging defines
* @brief compression/decompression debugging printing functions
*/
#ifndef CMP_DEBUG_H
......@@ -26,17 +26,16 @@
# define DEBUGLEVEL 0
#endif
#if !defined(ICU_ASW) && (defined(DEBUG) || DEBUGLEVEL > 0)
#include <stdio.h>
#define PRINT_BUFFER_SIZE 256
__extension__
#define debug_print(...) \
do { \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} while (0)
#if (defined(DEBUG) || DEBUGLEVEL > 0)
# define debug_print(...) cmp_debug_print_impl(__VA_ARGS__)
#else
#define debug_print(...) \
do {} while (0)
# define debug_print(...) do {} while (0)
#endif
void cmp_debug_print_impl(const char *fmt, ...);
#endif /* CMP_DEBUG_H */
......@@ -1863,23 +1863,7 @@ int cmp_ent_write_cmp_pars(struct cmp_entity *ent, const struct cmp_cfg *cfg,
if (cmp_ent_set_ima_golomb_par(ent, cfg->golomb_par))
return -1;
break;
case DATA_TYPE_OFFSET:
case DATA_TYPE_F_CAM_OFFSET:
case DATA_TYPE_BACKGROUND:
case DATA_TYPE_F_CAM_BACKGROUND:
case DATA_TYPE_SMEARING:
case DATA_TYPE_S_FX:
case DATA_TYPE_S_FX_EFX:
case DATA_TYPE_S_FX_NCOB:
case DATA_TYPE_S_FX_EFX_NCOB_ECOB:
case DATA_TYPE_L_FX:
case DATA_TYPE_L_FX_EFX:
case DATA_TYPE_L_FX_NCOB:
case DATA_TYPE_L_FX_EFX_NCOB_ECOB:
case DATA_TYPE_F_FX:
case DATA_TYPE_F_FX_EFX:
case DATA_TYPE_F_FX_NCOB:
case DATA_TYPE_F_FX_EFX_NCOB_ECOB:
case DATA_TYPE_CHUNK:
if (cmp_ent_set_non_ima_cmp_par1(ent, cfg->cmp_par_1))
return -1;
if (cmp_ent_set_non_ima_spill1(ent, cfg->spill_par_1))
......@@ -1911,6 +1895,24 @@ int cmp_ent_write_cmp_pars(struct cmp_entity *ent, const struct cmp_cfg *cfg,
return -1;
break;
/* the compression entity data type field only supports imagette or chunk data types*/
case DATA_TYPE_OFFSET:
case DATA_TYPE_F_CAM_OFFSET:
case DATA_TYPE_BACKGROUND:
case DATA_TYPE_F_CAM_BACKGROUND:
case DATA_TYPE_SMEARING:
case DATA_TYPE_S_FX:
case DATA_TYPE_S_FX_EFX:
case DATA_TYPE_S_FX_NCOB:
case DATA_TYPE_S_FX_EFX_NCOB_ECOB:
case DATA_TYPE_L_FX:
case DATA_TYPE_L_FX_EFX:
case DATA_TYPE_L_FX_NCOB:
case DATA_TYPE_L_FX_EFX_NCOB_ECOB:
case DATA_TYPE_F_FX:
case DATA_TYPE_F_FX_EFX:
case DATA_TYPE_F_FX_NCOB:
case DATA_TYPE_F_FX_EFX_NCOB_ECOB:
case DATA_TYPE_UNKNOWN:
default:
return -1;
......
......@@ -37,13 +37,6 @@
#endif
/**
* Compile time check usable outside of function scope.
* Stolen from Linux (hpi_internal.h)
*/
#define compile_time_assert(cond, msg) typedef char ASSERT_##msg[(cond) ? 1 : -1]
/**
* same with the stuff below
*/
......@@ -127,7 +120,7 @@
* It also tries to prevent the actual use of the "unused" variables.
*/
#if GNUC_PREREQ(4, 5)
#if GNUC_PREREQ(4, 5) || defined(__clang__)
#define UNUSED __attribute__((unused)) \
__attribute__((deprecated ("parameter declared as UNUSED")))
#elif defined(__GNUC__)
......@@ -154,4 +147,11 @@
#endif
/**
* Compile time check usable outside of function scope.
* Stolen from Linux (hpi_internal.h)
*/
#define compile_time_assert(cond, msg) UNUSED typedef char ASSERT_##msg[(cond) ? 1 : -1]
#endif /* COMPILER_H */
......@@ -49,6 +49,8 @@
# define PRIX32 "lX"
#endif /*PRIX32*/
#if 0
/* sparc-elf-gcc (BCC 4.4.2 release 1.0.50) does not support printf for long long types */
#ifndef PRId64
# define PRId64 "lld"
#endif /*PRId64*/
......@@ -72,6 +74,7 @@
#ifndef PRIX64
# define PRIX64 "llX"
#endif /*PRIX64*/
#endif
#endif /* __sparc__ */
......
common_sources = files([
'cmp_data_types.c',
'cmp_debug.c',
'cmp_entity.c',
'cmp_max_used_bits.c',
'cmp_support.c'
'cmp_support.c',
'vsnprintf.c'
])
This diff is collapsed.
/**
* @file vsnprintf.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 Tiny vsnprintf implementation
*/
#ifndef VSNPRINTF_H
#define VSNPRINTF_H
int my_vsnprintf(char* buffer, size_t count, const char* format, va_list va);
#endif /* VSNPRINTF_H */
......@@ -1990,8 +1990,9 @@ static int cmp_ent_read_header(struct cmp_entity *ent, struct cmp_cfg *cfg)
return -1;
cfg->data_type = cmp_ent_get_data_type(ent);
if (cmp_data_type_is_invalid(cfg->data_type)) {
debug_print("Error: Compression data type not supported.");
/* the compression entity data type field only supports imagette or chunk data types */
if (cfg->data_type != DATA_TYPE_CHUNK && !rdcu_supported_data_type_is_used(cfg->data_type)) {
debug_print("Error: Compression entity data type not supported.");
return -1;
}
......
......@@ -106,8 +106,15 @@ static const uint32_t BIT_MASK[] = {
static __inline uint64_t bit_read_unaligned_64be(const void *ptr)
{
#ifdef __sparc__
uint64_t v;
memcpy(&v, ptr, sizeof(v));
return cpu_to_be64(v);
#else
typedef __attribute__((aligned(1))) uint64_t unalign64;
return cpu_to_be64(*(const unalign64*)ptr);
#endif
}
......@@ -184,7 +191,6 @@ static __inline size_t bit_init_decoder(struct bit_decoder *dec, const void *buf
*
* @returns extracted value
*/
static __inline uint64_t bit_peek_bits(const struct bit_decoder *dec, unsigned int nb_bits)
{
/* mask for the shift value register to prevent undefined behaviour */
......
......@@ -1653,9 +1653,9 @@ int rdcu_write_sram_16(const uint16_t *buf, uint32_t addr, uint32_t size)
if (addr + size > RDCU_SRAM_START + RDCU_SRAM_SIZE)
return -1;
#if !(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#ifdef __BIG_ENDIAN
return rdcu_write_sram(buf, addr, size);
#else
#elif defined(__LITTLE_ENDIAN)
{
uint32_t i;
......@@ -1666,7 +1666,9 @@ int rdcu_write_sram_16(const uint16_t *buf, uint32_t addr, uint32_t size)
}
}
return (int)size; /* lol */
#endif /* __BYTE_ORDER__ */
#else
#error "Unknown byte order!"
#endif
}
......@@ -1699,9 +1701,9 @@ int rdcu_write_sram_32(const uint32_t *buf, uint32_t addr, uint32_t size)
if (addr + size > RDCU_SRAM_START + RDCU_SRAM_SIZE)
return -1;
#if !(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#ifdef __BIG_ENDIAN
return rdcu_write_sram(buf, addr, size);
#else
#elif defined(__LITTLE_ENDIAN)
{
uint32_t i;
......@@ -1712,7 +1714,9 @@ int rdcu_write_sram_32(const uint32_t *buf, uint32_t addr, uint32_t size)
}
}
return (int)size; /* lol */
#endif /* __BYTE_ORDER__ */
#else
#error "Unknown byte order!"
#endif
}
......
......@@ -292,7 +292,7 @@ static int rdcu_process_rx(void)
uint8_t crc8;
/* convert endianness in-place if needed */
#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#ifdef __LITTLE_ENDIAN
{
uint32_t i, tmp;
......@@ -302,7 +302,7 @@ static int rdcu_process_rx(void)
memcpy(&rp->data[i], &tmp, sizeof(tmp));
}
}
#endif /* __BYTE_ORDER__ */
#endif /* __LITTLE_ENDIAN */
crc8 = rmap_crc8(rp->data, rp->data_len);
if (crc8 != rp->data_crc) {
......@@ -471,7 +471,7 @@ int rdcu_sync(int (*fn)(uint16_t trans_id, uint8_t *cmd),
}
/* convert endianness if needed */
#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#ifdef __LITTLE_ENDIAN
if (data_len) {
uint32_t i;
uint32_t *tmp_buf = alloca(data_len);
......@@ -482,7 +482,7 @@ int rdcu_sync(int (*fn)(uint16_t trans_id, uint8_t *cmd),
addr = tmp_buf;
}
#endif /* __BYTE_ORDER__ */
#endif /* __LITTLE_ENDIAN */
n = rdcu_submit_tx(rmap_cmd, (uint32_t)n, addr, data_len);
free(rmap_cmd);
......
......@@ -23,6 +23,7 @@
#include <stddef.h>
#include "../common/compiler.h"
#include "../common/byteorder.h"
/**
* valid RMAP command codes, see Table 5-1 of ECSS‐E‐ST‐50‐52C
......@@ -142,12 +143,12 @@
__extension__
struct rmap_instruction {
#if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#ifdef __BIG_ENDIAN
uint8_t reserved:1;
uint8_t cmd_resp:1;
uint8_t cmd:4;
uint8_t reply_addr_len:2;
#elif (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#elif defined (__LITTLE_ENDIAN)
uint8_t reply_addr_len:2;
uint8_t cmd:4;
uint8_t cmd_resp:1;
......
This diff is collapsed.
......@@ -24,12 +24,20 @@
#include <compiler.h>
#include <cmp_entity.h>
#include <cmp_data_types.h>
#include "../../lib/icu_compress/cmp_icu.c" /* .c file included to test static functions */
#include "../../lib/decompress/decmp.c" /* .c file included to test static functions */
#define MAX_VALID_CW_LEM 32
/**
* @test bit_init_decoder
* @test bit_read_bits32
* @test bit_read_bits
* @test bit_refill
*/
void test_bitstream(void)
{
uint8_t i, data[12];
......@@ -95,8 +103,6 @@ void test_bitstream(void)
bit_read_bits(&dec, 57);
TEST_ASSERT_EQUAL_INT(BIT_OVERFLOW, status);
{
uint8_t k, j;
uint8_t buf[9];
......@@ -197,8 +203,8 @@ void test_unary_decoder(void)
TEST_ASSERT_EQUAL_INT(32, leading_ones);
TEST_ASSERT_EQUAL_INT(BIT_OVERFLOW, bit_refill(&dec));
{
uint64_t value64 = ~0ULL;
{ uint64_t value64 = ~0ULL;
ret = bit_init_decoder(&dec, &value64, sizeof(value64));
TEST_ASSERT_EQUAL_size_t(sizeof(value64), ret);
leading_ones = unary_decoder(&dec, unused_1, unused_2);
......@@ -790,8 +796,7 @@ void test_decode_multi(void)
TEST_ASSERT_EQUAL_INT(-1, err);
/* 0xFA -> 16 = spill(8)+8 -> unencoded_len = 17 bits -> larger than
* 16 bit max_used_bits*/
/* 0xFA -> 16 = spill(8)+8 -> unencoded_len = 17 bits -> larger than 16 bit max_used_bits */
cmp_data[0] = cpu_to_be32(0xFA000000);
cmp_data[1] = cpu_to_be32(0x00000000);
bit_init_decoder(&dec, cmp_data, sizeof(cmp_data));
......@@ -888,6 +893,7 @@ void test_multi_refill_needed(void)
TEST_ASSERT_EQUAL_INT(CORRUPTION_DETECTED, err);
}
/**
* @test re_map_to_pos
*/
......@@ -920,6 +926,7 @@ void test_re_map_to_pos(void)
for (j = -16; j < 15; j++) {
uint32_t map_val = map_to_pos((uint32_t)j, 16) & 0x3F;
result = re_map_to_pos(map_val);
TEST_ASSERT_EQUAL_INT32(j, result);
}
......@@ -980,7 +987,8 @@ size_t icu_compress_data_entity(struct cmp_entity *ent, const struct cmp_cfg *cf
return 0;
/* XXX overwrite the size of the compression entity with the size of the actual
* size of the compressed data; not all allocated memory is normally used */
* size of the compressed data; not all allocated memory is normally used
*/
s = cmp_ent_create(ent, cfg->data_type, cfg->cmp_mode == CMP_MODE_RAW,
cmp_bit_to_byte((unsigned int)cmp_size_bits));
......@@ -1065,8 +1073,7 @@ void test_decompress_imagette_model(void)
bit_init_decoder(&dec, cfg.icu_output_buf, cfg.buffer_length);
err = decompress_imagette(&cfg, &dec);
/* TEST_ASSERT_EQUAL_INT(15, stream_pos); */
err = decompress_imagette(&cfg, &dec, RDCU_DECOMPRESSION);
TEST_ASSERT_FALSE(err);
TEST_ASSERT_EQUAL_HEX(1, data[0]);
TEST_ASSERT_EQUAL_HEX(2, data[1]);
......@@ -1082,189 +1089,6 @@ void test_decompress_imagette_model(void)
}
#define DATA_SAMPLES 5
void test_cmp_decmp_s_fx_diff(void)
{
size_t s;
int err, decmp_size;
struct cmp_entity *ent;
const uint32_t MAX_VALUE = ~(~0U << MAX_USED_BITS_V1.s_fx);
struct s_fx data_entry[DATA_SAMPLES];
uint8_t data_to_compress[COLLECTION_HDR_SIZE + sizeof(data_entry)];
struct s_fx *decompressed_data = NULL;
uint32_t compressed_data_len_samples = DATA_SAMPLES;
struct cmp_cfg cfg;
data_entry[0].exp_flags = 0;
data_entry[0].fx = 0;
data_entry[1].exp_flags = 1;
data_entry[1].fx = 23;
data_entry[2].exp_flags = 2;
data_entry[2].fx = 42;
data_entry[3].exp_flags = 3;
data_entry[3].fx = MAX_VALUE;
data_entry[4].exp_flags = 3;
data_entry[4].fx = MAX_VALUE>>1;
for (s = 0; s < COLLECTION_HDR_SIZE; s++)
data_to_compress[s] = (uint8_t)s;
memcpy(&data_to_compress[COLLECTION_HDR_SIZE], data_entry, sizeof(data_entry));
cfg = cmp_cfg_icu_create(DATA_TYPE_S_FX, CMP_MODE_DIFF_MULTI,
CMP_PAR_UNUSED, CMP_LOSSLESS);
TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN);
s = cmp_cfg_icu_buffers(&cfg, data_to_compress, DATA_SAMPLES, NULL, NULL,
NULL, compressed_data_len_samples);
TEST_ASSERT_TRUE(s);
err = cmp_cfg_fx_cob(&cfg, 2, 6, 4, 14, CMP_PAR_UNUSED, CMP_PAR_UNUSED,
CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED,
CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED);
TEST_ASSERT_FALSE(err);
s = icu_compress_data_entity(NULL, &cfg);
TEST_ASSERT_TRUE(s);
ent = malloc(s); TEST_ASSERT_TRUE(ent);
s = icu_compress_data_entity(ent, &cfg);
TEST_ASSERT_TRUE(s);
/* now decompress the data */
decmp_size = decompress_cmp_entiy(ent, NULL, NULL, decompressed_data);
TEST_ASSERT_EQUAL_INT(cmp_cal_size_of_data(cfg.samples, cfg.data_type), decmp_size);
decompressed_data = malloc((size_t)decmp_size); TEST_ASSERT_TRUE(decompressed_data);
decmp_size = decompress_cmp_entiy(ent, NULL, NULL, decompressed_data);
TEST_ASSERT_EQUAL_INT(cmp_cal_size_of_data(cfg.samples, cfg.data_type), decmp_size);
TEST_ASSERT_EQUAL_HEX8_ARRAY(data_to_compress, decompressed_data, decmp_size);
/* TEST_ASSERT_FALSE(memcmp(data_to_compress, decompressed_data, (size_t)decmp_size)); */
/* for (i = 0; i < samples; ++i) { */
/* printf("%u == %u (round: %u)\n", data[i], decompressed_data[i], round); */
/* uint32_t mask = ~0U << round; */
/* if ((data[i]&mask) != (decompressed_data[i]&mask)) */
/* TEST_ASSERT(0); */
/* if (model_mode_is_used(cmp_mode)) */
/* if (up_model[i] != de_up_model[i]) */
/* TEST_ASSERT(0); */
/* } */
free(ent);
free(decompressed_data);
}
#undef DATA_SAMPLES
void test_s_fx_diff(void)
{
size_t i;
int s;
uint8_t cmp_entity[88] = {
0x80, 0x00, 0x00, 0x09, 0x00, 0x00, 0x58, 0x00, 0x00, 0x20, 0x04, 0xEE, 0x21, 0xBD, 0xB0, 0x1C, 0x04, 0xEE, 0x21, 0xBD, 0xB0, 0x41, 0x00, 0x08, 0x02, 0x08, 0xD0, 0x10, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0xAE, 0xDE, 0x00, 0x00, 0x00, 0x73, 0xFF, 0xFF, 0xF8, 0x00, 0x00, 0x00,
};
uint8_t result_data[32] = {0};
struct collection_hdr *hdr = (struct collection_hdr *)result_data;
struct s_fx *data = (struct s_fx *)hdr->entry;
uint8_t *decompressed_data;
/* put some dummy data in the header*/
for (i = 0; i < sizeof(*hdr); i++)
result_data[i] = (uint8_t)i;
data[0].exp_flags = 0;
data[0].fx = 0;
data[1].exp_flags = 1;
data[1].fx = 0xFFFFFF;
data[2].exp_flags = 3;
data[2].fx = 0x7FFFFF;
data[3].exp_flags = 0;
data[3].fx = 0;
s = decompress_cmp_entiy((void *)cmp_entity, NULL, NULL, NULL);
TEST_ASSERT_EQUAL_INT(sizeof(result_data), s);
decompressed_data = malloc((size_t)s);
TEST_ASSERT_TRUE(decompressed_data);
s = decompress_cmp_entiy((void *)cmp_entity, NULL, NULL, decompressed_data);
TEST_ASSERT_EQUAL_INT(sizeof(result_data), s);
for (i = 0; i < (size_t)s; ++i) {
TEST_ASSERT_EQUAL(result_data[i], decompressed_data[i]);
}
free(decompressed_data);
}
void test_s_fx_model(void)
{
size_t i;
int s;
uint8_t compressed_data_buf[92] = {
0x80, 0x00, 0x00, 0x09, 0x00, 0x00, 0x5C, 0x00, 0x00, 0x20, 0x04, 0xF0, 0xC2, 0xD3, 0x47, 0xE4, 0x04, 0xF0, 0xC2, 0xD3, 0x48, 0x16, 0x00, 0x08, 0x03, 0x08, 0xD0, 0x10, 0x01, 0x01, 0x00, 0x00,
0x00, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x3B, 0xFF, 0xFF, 0xEF, 0xFF, 0xFF, 0x5B, 0xFF, 0xFF, 0xEF, 0xFF, 0xFF, 0x5D, 0x80, 0x00, 0x00,
};
struct cmp_entity *cmp_entity = (struct cmp_entity *)compressed_data_buf;
uint8_t model_buf[32];
uint8_t decompressed_data[32];
uint8_t up_model_buf[32];
uint8_t exp_data_buf[32] = {0}; /* expected uncompressed data */
uint8_t exp_up_model_buf[32] = {0};
struct collection_hdr *model_collection = (struct collection_hdr *)model_buf;
struct s_fx *model_data = (struct s_fx *)model_collection->entry;
struct collection_hdr *exp_data_collection;
struct s_fx *exp_data;
struct collection_hdr *exp_up_model_collection;
struct s_fx *exp_updated_model_data;
memset(model_collection, 0xFF, sizeof(*model_collection));
model_data[0].exp_flags = 0;
model_data[0].fx = 0;
model_data[1].exp_flags = 3;
model_data[1].fx = 0x7FFFFF;
model_data[2].exp_flags = 0;
model_data[2].fx = 0xFFFFFF;
model_data[3].exp_flags = 3;
model_data[3].fx = 0xFFFFFF;
exp_data_collection = (struct collection_hdr *)exp_data_buf;
exp_data = (struct s_fx *)exp_data_collection->entry;
/* put some dummy data in the header */
for (i = 0; i < sizeof(*exp_data_collection); i++)
exp_data_buf[i] = (uint8_t)i;
exp_data[0].exp_flags = 0;
exp_data[0].fx = 0;
exp_data[1].exp_flags = 1;
exp_data[1].fx = 0xFFFFFF;
exp_data[2].exp_flags = 3;
exp_data[2].fx = 0x7FFFFF;
exp_data[3].exp_flags = 0;
exp_data[3].fx = 0;
exp_up_model_collection = (struct collection_hdr *)exp_up_model_buf;
exp_updated_model_data = (struct s_fx *)exp_up_model_collection->entry;
/* put some dummy data in the header*/
for (i = 0; i < sizeof(*exp_up_model_collection); i++)
exp_up_model_buf[i] = (uint8_t)i;
exp_updated_model_data[0].exp_flags = 0;
exp_updated_model_data[0].fx = 0;
exp_updated_model_data[1].exp_flags = 2;
exp_updated_model_data[1].fx = 0xBFFFFF;
exp_updated_model_data[2].exp_flags = 1;
exp_updated_model_data[2].fx = 0xBFFFFF;
exp_updated_model_data[3].exp_flags = 1;
exp_updated_model_data[3].fx = 0x7FFFFF;
s = decompress_cmp_entiy(cmp_entity, model_buf, up_model_buf, decompressed_data);
TEST_ASSERT_EQUAL_INT(sizeof(exp_data_buf), s);
TEST_ASSERT_FALSE(memcmp(exp_data_buf, decompressed_data, sizeof(exp_data_buf)));
TEST_ASSERT_FALSE(memcmp(exp_up_model_buf, up_model_buf, sizeof(exp_up_model_buf)));
}
/**
* @test cmp_ent_write_cmp_pars
* @test cmp_ent_read_header
......@@ -1421,130 +1245,6 @@ void test_cmp_ent_write_cmp_pars(void)
memset(&cfg, 0, sizeof(struct cmp_cfg));
memset(&cfg_read, 0, sizeof(struct cmp_cfg));
/** flux cob data type test **/
/* create configuration */
cfg.data_type = DATA_TYPE_S_FX_EFX_NCOB_ECOB;
cfg.cmp_mode = CMP_MODE_MODEL_ZERO;
cfg.model_value = 11;
cfg.round = 2;
cfg.samples = 9;
cfg.spill_exp_flags = 1;
cfg.spill_fx = 2;
cfg.spill_ncob = 3;
cfg.spill_efx = 4;
cfg.spill_ecob = 5;
cfg.spill_fx_cob_variance = 6;
cfg.cmp_par_exp_flags = 7;
cfg.cmp_par_fx = 8;
cfg.cmp_par_ncob = 9;
cfg.cmp_par_efx = 10;
cfg.cmp_par_ecob = 11;
cfg.cmp_par_fx_cob_variance = 12;
cfg.max_used_bits = cmp_max_used_bits_list_get(42);
/* create a compression entity */
size = cmp_ent_create(NULL, cfg.data_type, cfg.cmp_mode == CMP_MODE_RAW, 12);
TEST_ASSERT_NOT_EQUAL_INT(0, size);
ent = malloc(size); TEST_ASSERT_NOT_NULL(ent);
size = cmp_ent_create(ent, cfg.data_type, cfg.cmp_mode == CMP_MODE_RAW, 12);
TEST_ASSERT_NOT_EQUAL_INT(0, size);
error = cmp_ent_write_cmp_pars(ent, &cfg, cmp_size_bits);
TEST_ASSERT_FALSE(error);
TEST_ASSERT_EQUAL_INT(cfg.data_type, cmp_ent_get_data_type(ent));
TEST_ASSERT_EQUAL_INT(0, cmp_ent_get_data_type_raw_bit(ent));
TEST_ASSERT_EQUAL_INT(12, cmp_ent_get_cmp_data_size(ent));
TEST_ASSERT_EQUAL_INT(cmp_cal_size_of_data(cfg.samples, cfg.data_type), cmp_ent_get_original_size(ent));
TEST_ASSERT_EQUAL_INT(cfg.cmp_mode, cmp_ent_get_cmp_mode(ent));
TEST_ASSERT_EQUAL_INT(cfg.model_value, cmp_ent_get_model_value(ent));
TEST_ASSERT_EQUAL_INT(max_used_bits.version, cmp_ent_get_max_used_bits_version(ent));
TEST_ASSERT_EQUAL_INT(cfg.round, cmp_ent_get_lossy_cmp_par(ent));
TEST_ASSERT_EQUAL_INT(cfg.spill_exp_flags, cmp_ent_get_non_ima_spill1(ent));
TEST_ASSERT_EQUAL_INT(cfg.spill_fx, cmp_ent_get_non_ima_spill2(ent));
TEST_ASSERT_EQUAL_INT(cfg.spill_ncob, cmp_ent_get_non_ima_spill3(ent));
TEST_ASSERT_EQUAL_INT(cfg.spill_efx, cmp_ent_get_non_ima_spill4(ent));
TEST_ASSERT_EQUAL_INT(cfg.spill_ecob, cmp_ent_get_non_ima_spill5(ent));
TEST_ASSERT_EQUAL_INT(cfg.spill_fx_cob_variance, cmp_ent_get_non_ima_spill6(ent));
TEST_ASSERT_EQUAL_INT(cfg.cmp_par_exp_flags, cmp_ent_get_non_ima_cmp_par1(ent));
TEST_ASSERT_EQUAL_INT(cfg.cmp_par_fx, cmp_ent_get_non_ima_cmp_par2(ent));
TEST_ASSERT_EQUAL_INT(cfg.cmp_par_ncob, cmp_ent_get_non_ima_cmp_par3(ent));
TEST_ASSERT_EQUAL_INT(cfg.cmp_par_efx, cmp_ent_get_non_ima_cmp_par4(ent));
TEST_ASSERT_EQUAL_INT(cfg.cmp_par_ecob, cmp_ent_get_non_ima_cmp_par5(ent));
TEST_ASSERT_EQUAL_INT(cfg.cmp_par_fx_cob_variance, cmp_ent_get_non_ima_cmp_par6(ent));
error = cmp_ent_read_header(ent, &cfg_read);
TEST_ASSERT_FALSE(error);
cfg.icu_output_buf = cmp_ent_get_data_buf(ent); /* quick fix that both cfg are equal */
cfg.buffer_length = 12; /* quick fix that both cfg are equal */
TEST_ASSERT_EQUAL_MEMORY(&cfg, &cfg_read, sizeof(struct cmp_cfg));
free(ent);
memset(&cfg, 0, sizeof(struct cmp_cfg));
memset(&cfg_read, 0, sizeof(struct cmp_cfg));
/** auxiliary data data_type test **/
/* create configuration */
cfg.data_type = DATA_TYPE_SMEARING;
cfg.cmp_mode = CMP_MODE_MODEL_ZERO;
cfg.model_value = 11;
cfg.round = 2;
cfg.samples = 9;
cfg.spill_smearing_mean = 1;
cfg.spill_smearing_variance = 2;
cfg.spill_smearing_pixels_error = 3;
cfg.cmp_par_smearing_mean = 7;
cfg.cmp_par_smearing_variance = 8;
cfg.cmp_par_smearing_pixels_error = 9;
cfg.max_used_bits = cmp_max_used_bits_list_get(42);
/* create a compression entity */
size = cmp_ent_create(NULL, cfg.data_type, cfg.cmp_mode == CMP_MODE_RAW, 12);
TEST_ASSERT_NOT_EQUAL_INT(0, size);
ent = malloc(size); TEST_ASSERT_NOT_NULL(ent);
size = cmp_ent_create(ent, cfg.data_type, cfg.cmp_mode == CMP_MODE_RAW, 12);
TEST_ASSERT_NOT_EQUAL_INT(0, size);
error = cmp_ent_write_cmp_pars(ent, &cfg, cmp_size_bits);
TEST_ASSERT_FALSE(error);
TEST_ASSERT_EQUAL_INT(cfg.data_type, cmp_ent_get_data_type(ent));
TEST_ASSERT_EQUAL_INT(0, cmp_ent_get_data_type_raw_bit(ent));
TEST_ASSERT_EQUAL_INT(12, cmp_ent_get_cmp_data_size(ent));
TEST_ASSERT_EQUAL_INT(cmp_cal_size_of_data(cfg.samples, cfg.data_type), cmp_ent_get_original_size(ent));
TEST_ASSERT_EQUAL_INT(cfg.cmp_mode, cmp_ent_get_cmp_mode(ent));
TEST_ASSERT_EQUAL_INT(cfg.model_value, cmp_ent_get_model_value(ent));
TEST_ASSERT_EQUAL_INT(max_used_bits.version, cmp_ent_get_max_used_bits_version(ent));
TEST_ASSERT_EQUAL_INT(cfg.round, cmp_ent_get_lossy_cmp_par(ent));
TEST_ASSERT_EQUAL_INT(0, cmp_ent_get_non_ima_spill1(ent));
TEST_ASSERT_EQUAL_INT(0, cmp_ent_get_non_ima_spill2(ent));
TEST_ASSERT_EQUAL_INT(0, cmp_ent_get_non_ima_spill3(ent));
TEST_ASSERT_EQUAL_INT(cfg.spill_smearing_mean, cmp_ent_get_non_ima_spill4(ent));
TEST_ASSERT_EQUAL_INT(cfg.spill_smearing_variance, cmp_ent_get_non_ima_spill5(ent));
TEST_ASSERT_EQUAL_INT(cfg.spill_smearing_pixels_error, cmp_ent_get_non_ima_spill6(ent));
TEST_ASSERT_EQUAL_INT(0, cmp_ent_get_non_ima_cmp_par1(ent));
TEST_ASSERT_EQUAL_INT(0, cmp_ent_get_non_ima_cmp_par2(ent));
TEST_ASSERT_EQUAL_INT(0, cmp_ent_get_non_ima_cmp_par3(ent));
TEST_ASSERT_EQUAL_INT(cfg.cmp_par_smearing_mean, cmp_ent_get_non_ima_cmp_par4(ent));
TEST_ASSERT_EQUAL_INT(cfg.cmp_par_smearing_variance, cmp_ent_get_non_ima_cmp_par5(ent));
TEST_ASSERT_EQUAL_INT(cfg.cmp_par_smearing_pixels_error, cmp_ent_get_non_ima_cmp_par6(ent));
error = cmp_ent_read_header(ent, &cfg_read);
TEST_ASSERT_FALSE(error);
cfg.icu_output_buf = cmp_ent_get_data_buf(ent); /* quick fix that both cfg are equal */
cfg.buffer_length = 12; /* quick fix that both cfg are equal */
TEST_ASSERT_EQUAL_MEMORY(&cfg, &cfg_read, sizeof(struct cmp_cfg));
free(ent);
memset(&cfg, 0, sizeof(struct cmp_cfg));
memset(&cfg_read, 0, sizeof(struct cmp_cfg));
/** Error Cases **/
/* create imagette raw mode configuration */
cfg.data_type = DATA_TYPE_IMAGETTE;
......@@ -1796,8 +1496,8 @@ void test_cmp_ent_write_cmp_pars(void)
TEST_ASSERT_TRUE(error);
/* test data type = DATA_TYPE_F_CAM_BACKGROUND +1 */
cmp_ent_set_data_type(ent, DATA_TYPE_F_CAM_BACKGROUND + 1, 0);
cfg.data_type = DATA_TYPE_F_CAM_BACKGROUND + 1;
cmp_ent_set_data_type(ent, DATA_TYPE_F_CAM_BACKGROUND + 10, 0);
cfg.data_type = DATA_TYPE_F_CAM_BACKGROUND + 10;
error = cmp_ent_write_cmp_pars(ent, &cfg, cmp_size_bits);
TEST_ASSERT_TRUE(error);
free(ent);
......@@ -2032,6 +1732,56 @@ void test_cmp_ent_read_header_error_cases(void)
}
/**
* @test decompress_cmp_entiy
*/
void test_decompress_imagette_chunk_raw(void)
{
int decmp_size;
size_t i;
uint16_t data[] = {0, 1, 2, 0x42, (uint16_t)INT16_MIN, INT16_MAX, UINT16_MAX};
uint8_t *decompressed_data;
struct cmp_entity *ent;
uint32_t ent_size;
uint32_t chunk_size = 2*(COLLECTION_HDR_SIZE + sizeof(data));
uint8_t *chunk = calloc(1, chunk_size); TEST_ASSERT_TRUE(chunk);
for (i = 0; i < 2; i++) {
struct collection_hdr *col = (struct collection_hdr *)(chunk+chunk_size/2*i);
TEST_ASSERT_FALSE(cmp_col_set_subservice(col, SST_NCxx_S_SCIENCE_IMAGETTE));
TEST_ASSERT_FALSE(cmp_col_set_data_length(col, sizeof(data)));
TEST_ASSERT_FALSE(cmp_col_set_timestamp(col, 0x0102030400607));
memcpy(col->entry, data, sizeof(data));
}
ent_size = cmp_ent_create(NULL, DATA_TYPE_CHUNK, 1, chunk_size);
TEST_ASSERT_EQUAL_INT(GENERIC_HEADER_SIZE+chunk_size, ent_size);
ent = malloc(ent_size); TEST_ASSERT_TRUE(ent);
ent_size = cmp_ent_create(ent, DATA_TYPE_CHUNK, 1, chunk_size);
TEST_ASSERT_EQUAL_INT(GENERIC_HEADER_SIZE+chunk_size, ent_size);
TEST_ASSERT_FALSE(cmp_ent_set_original_size(ent, chunk_size));
memcpy(cmp_ent_get_data_buf(ent), chunk, chunk_size);
TEST_ASSERT_FALSE(cpu_to_be_chunk(cmp_ent_get_data_buf(ent), chunk_size));
decmp_size = decompress_cmp_entiy(ent, NULL, NULL, NULL);
TEST_ASSERT_EQUAL_INT(chunk_size, decmp_size);
decompressed_data = malloc((size_t)decmp_size);
TEST_ASSERT_TRUE(decompressed_data);
decmp_size = decompress_cmp_entiy(ent, NULL, NULL, decompressed_data);
TEST_ASSERT_EQUAL_INT(chunk_size, decmp_size);
for (i = 0; i < chunk_size; ++i)
TEST_ASSERT_EQUAL_INT(chunk[i], decompressed_data[i]);
free(chunk);
free(ent);
free(decompressed_data);
}
void test_decompression_error_cases(void)
{
/* TODO: error cases model decompression without a model Buffer */
......
......@@ -4,5 +4,5 @@ pcb_dep = pcg_proj.get_variable('libpcg_basic_dep')
test_common_lib = static_library(
'test_common',
'test_common.c',
dependencies: pcb_dep,
dependencies: [pcb_dep, unity_dep]
)
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "pcg_basic.h"
#include <unity.h>
void cmp_rand_seed(uint64_t seed)
{
......@@ -27,7 +31,7 @@ uint32_t cmp_rand32(void)
uint32_t cmp_rand_between(uint32_t min, uint32_t max)
{
assert(min < max);
TEST_ASSERT(min < max);
return min + pcg32_boundedrand(max-min+1);
}
......@@ -35,7 +39,26 @@ uint32_t cmp_rand_between(uint32_t min, uint32_t max)
uint32_t cmp_rand_nbits(unsigned int nbits)
{
assert(nbits > 0);
TEST_ASSERT(nbits > 0);
return cmp_rand32() >> (32 - nbits);
}
/**
* @brief allocates memory safely for tests
*
* @param size The size of memory to allocate.
*
* @returns a pointer to the allocated memory, or NULL if allocation fails
*/
void* TEST_malloc(size_t size)
{
if (size > 0) {
void* const mem = malloc(size);
TEST_ASSERT(mem);
return mem;
}
return NULL;
}
......@@ -2,6 +2,7 @@
#define TEST_COMMON_H
#include <stdint.h>
#include <stddef.h>
void cmp_rand_seed(uint64_t seed);
......@@ -11,4 +12,6 @@ uint32_t cmp_rand_between(uint32_t min, uint32_t max);
uint32_t cmp_rand_nbits(unsigned int nbits);
void* TEST_malloc(size_t size);
#endif /* TEST_COMMON_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment