Skip to content

Commit

Permalink
Fix reg_validate()
Browse files Browse the repository at this point in the history
  • Loading branch information
matwey committed Aug 4, 2019
1 parent 98ee691 commit ff65b42
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int reg_validate(struct reg* reg) {
size_t i = 0;

for (i = 0; i < REG_MAX; ++i) {
if (reg->addr[REG_MAX] == 0xffff) {
if (reg->addr[i] == 0xffff) {
reg->error_str = "Missed register address";
return -1;
}
Expand Down
39 changes: 37 additions & 2 deletions test/reg.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
#include <check.h>
#include <stdlib.h>

#include <fwpkg.h>
#include <reg.h>

struct fwpkg fwpkg;
char* map = NULL;

void setup() {
int ret = 0;
size_t map_size = 0;

ret = fwpkg_init_from_preload(&fwpkg);
ck_assert_int_eq(ret, 0);

map_size = fwpkg_map_size(&fwpkg)+1;
map = malloc(map_size);
ck_assert(map != NULL);

ret = fwpkg_read_map(&fwpkg, map, &map_size);
ck_assert_int_eq(ret, 0);
map[map_size] = '\0';
}

void teardown() {
free(map);
fwpkg_destroy(&fwpkg);
}

START_TEST (test_reg_from_map1) {
char x[] = "LEDS_OUT = 0x42";
struct reg reg;
ck_assert_int_eq(reg_init(&reg, x), 0);
ck_assert_int_eq(reg.addr[LEDS_OUT], 0x42);
ck_assert_int_eq(reg_init(&reg, x), -1);
}
END_TEST

START_TEST (test_reg_from_map2) {
struct reg reg;
ck_assert_int_eq(reg_init(&reg, map), 0);
ck_assert_int_eq(reg.addr[CSTREAM_CFG], 0x800);
ck_assert_int_eq(reg.addr[CSTREAM_CONS_LO], 0x801);
ck_assert_int_eq(reg.addr[CSTREAM_CONS_HI], 0x802);
}
END_TEST

Expand All @@ -19,7 +52,9 @@ Suite* range_suite(void) {

tc_core = tcase_create("Core");

tcase_add_unchecked_fixture(tc_core, setup, teardown);
tcase_add_test(tc_core, test_reg_from_map1);
tcase_add_test(tc_core, test_reg_from_map2);
suite_add_tcase(s, tc_core);

return s;
Expand Down

0 comments on commit ff65b42

Please sign in to comment.