summaryrefslogtreecommitdiff
path: root/cesar/mac
diff options
context:
space:
mode:
authorJérémy Dufour2010-09-14 10:53:26 +0200
committerJérémy Dufour2010-09-20 13:28:27 +0200
commit77aab22efc981835727eb68ac259692b789f7e4a (patch)
tree78ccfd0eccd3924757a94d5fe5678a4438758bad /cesar/mac
parenta0a0c90e9a49202fd284f3561249bf0c31b2591f (diff)
cesar/mac/common: in tonemap_copy, do not overwrite dst pointers, closes #1877
Diffstat (limited to 'cesar/mac')
-rw-r--r--cesar/mac/common/src/tonemap.c5
-rw-r--r--cesar/mac/common/test/tonemap/src/test_tonemap.c109
2 files changed, 112 insertions, 2 deletions
diff --git a/cesar/mac/common/src/tonemap.c b/cesar/mac/common/src/tonemap.c
index d11643377d..ebc6c0fca8 100644
--- a/cesar/mac/common/src/tonemap.c
+++ b/cesar/mac/common/src/tonemap.c
@@ -146,9 +146,10 @@ tonemap_copy (tonemap_t *dst, tonemap_t *src)
dbg_assert (src);
/* Copy first block. */
- memcpy (dst->tmdma_desc_head, src->tmdma_desc_head, BLK_SIZE);
+ memcpy (dst->tmdma_desc_head->data, src->tmdma_desc_head->data, BLK_SIZE);
/* Copy the second block. */
- memcpy (dst->tmdma_desc_head->next, src->tmdma_desc_head->next,
+ memcpy (dst->tmdma_desc_head->next->data,
+ src->tmdma_desc_head->next->data,
BLK_SIZE - TONEMAP_HEADER_POS_BYTE);
/* Copy header. */
blk_t *copy = dst->tmdma_desc_head;
diff --git a/cesar/mac/common/test/tonemap/src/test_tonemap.c b/cesar/mac/common/test/tonemap/src/test_tonemap.c
index b2134cd384..05f8f36865 100644
--- a/cesar/mac/common/test/tonemap/src/test_tonemap.c
+++ b/cesar/mac/common/test/tonemap/src/test_tonemap.c
@@ -480,6 +480,114 @@ tonemap_tonemask_test_case (test_t t)
}
void
+tonemap_copy_test (test_t t)
+{
+ test_case_begin (t, "tonemap_copy ()");
+
+ /* Random generator. */
+ lib_rnd_t rnd;
+ lib_rnd_init (&rnd, 1234);
+
+ /* Tone mask initialisation. */
+ tonemask_info_t ti;
+ tonemask_default (ti.tonemask);
+
+ /* Create a tone map. */
+ tonemap_t *tm = tonemap_alloc ();
+ /* Fill it with some values. */
+ tm->strict = false;
+ tm->cpf = true;
+ tm->fecrate = PHY_FEC_RATE_1_2;
+ tm->gil = PHY_GIL_NONE;
+ tm->ble = 0x42;
+ tm->bits_per_symbol = 0x4242;
+ tm->bits_per_pb[0] = 24;
+ tm->bits_per_pb[1] = 42;
+ tm->phy_combo_params[0] = 42;
+ tm->phy_combo_params[1] = 24;
+ tm->tcc_halfit = 0x1234;
+ tm->released = false;
+ tm->ber_target = -1;
+ tm->ber_target_reached = -2;
+ /* Fill the tone map with random values. */
+ u8 tones_list[PHY_CARRIER_NB];
+ uint tones_pos = 0;
+ TONEMAP_WRITE_BEGIN (tm, ti.tonemask)
+ {
+ tones_list[tones_pos] = lib_rnd_uniform (&rnd, 8);
+ TONEMAP_WRITE_MOD (tones_list[tones_pos]);
+ tones_pos++;
+ }
+ TONEMAP_WRITE_END;
+ /* Copy tone map. */
+ tonemap_t *tm_copy = tonemap_alloc ();
+ /* Backup a few things. */
+ blk_t *blk_tm[2] = { tm->tmdma_desc_head, tm->tmdma_desc_head->next };
+ blk_t *blk_tmc[2] = { tm_copy->tmdma_desc_head,
+ tm_copy->tmdma_desc_head->next };
+ tonemap_copy (tm_copy, tm);
+ test_begin (t, "copy does not overwrite pointers")
+ {
+ test_fail_if (blk_tm[0] != tm->tmdma_desc_head);
+ test_fail_if (blk_tm[1] != tm->tmdma_desc_head->next);
+ test_fail_if (blk_tmc[0] != tm_copy->tmdma_desc_head);
+ test_fail_if (blk_tmc[1] != tm_copy->tmdma_desc_head->next);
+ } test_end;
+ test_begin (t, "destination tone map is the same as source")
+ {
+ test_fail_if (tm_copy->strict != false);
+ test_fail_if (tm_copy->cpf != true);
+ test_fail_if (tm_copy->fecrate != PHY_FEC_RATE_1_2);
+ test_fail_if (tm_copy->gil != PHY_GIL_NONE);
+ test_fail_if (tm_copy->ble != 0x42);
+ test_fail_if (tm_copy->bits_per_symbol != 0x4242);
+ test_fail_if (tm_copy->bits_per_pb[0] != 24);
+ test_fail_if (tm_copy->bits_per_pb[1] != 42);
+ test_fail_if (tm_copy->phy_combo_params[0] != 42);
+ test_fail_if (tm_copy->phy_combo_params[1] != 24);
+ test_fail_if (tm_copy->tcc_halfit != 0x1234);
+ test_fail_if (tm_copy->released != false);
+ test_fail_if (tm_copy->ber_target != (u64) -1);
+ test_fail_if (tm_copy->ber_target_reached != (u64) -2);
+ tones_pos = 0;
+ u8 mod;
+ TONEMAP_READ_BEGIN (tm_copy, ti.tonemask, mod)
+ {
+ test_fail_if (mod != tones_list[tones_pos++]);
+ }
+ TONEMAP_READ_END;
+ } test_end;
+ test_begin (t, "source is not changed during copy")
+ {
+ test_fail_if (tm->strict != false);
+ test_fail_if (tm->cpf != true);
+ test_fail_if (tm->fecrate != PHY_FEC_RATE_1_2);
+ test_fail_if (tm->gil != PHY_GIL_NONE);
+ test_fail_if (tm->ble != 0x42);
+ test_fail_if (tm->bits_per_symbol != 0x4242);
+ test_fail_if (tm->bits_per_pb[0] != 24);
+ test_fail_if (tm->bits_per_pb[1] != 42);
+ test_fail_if (tm->phy_combo_params[0] != 42);
+ test_fail_if (tm->phy_combo_params[1] != 24);
+ test_fail_if (tm->tcc_halfit != 0x1234);
+ test_fail_if (tm->released != false);
+ test_fail_if (tm->ber_target != (u64) -1);
+ test_fail_if (tm->ber_target_reached != (u64) -2);
+ tones_pos = 0;
+ u8 mod;
+ TONEMAP_READ_BEGIN (tm, ti.tonemask, mod)
+ {
+ test_fail_if (mod != tones_list[tones_pos++]);
+ }
+ TONEMAP_READ_END;
+ } test_end;
+
+ /* Clean. */
+ tonemap_free (tm);
+ tonemap_free (tm_copy);
+}
+
+void
tonemaps_access_test (test_t t)
{
tonemaps_t *tms = tonemaps_alloc ();
@@ -575,6 +683,7 @@ tonemap_test_suite (test_t t)
tonemap_lookup_test_case (t);
tonemap_tonemask_test_case (t);
tonemap_access_test (t);
+ tonemap_copy_test (t);
tonemaps_access_test (t);
tonemaps_reset_test (t);