-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/pkg_nanors: add test for nanors
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
include ../Makefile.tests_common | ||
|
||
USEPKG += nanors | ||
USEMODULE += random | ||
|
||
CFLAGS += -DDATA_SHARDS_MAX=32 | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (C) 2022 ML!PA Consulting GmbH | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup tests | ||
* @{ | ||
* | ||
* @file | ||
* @brief Test application for Reed-Solomon codec | ||
* | ||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com> | ||
* @} | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include "kernel_defines.h" | ||
#include "random.h" | ||
#include "rs.h" | ||
|
||
#define DATA_SHARDS 20 | ||
#define RECOVERY_SHARDS 10 | ||
#define SHARD_SIZE 64 | ||
|
||
typedef reed_solomon rs_t; | ||
|
||
int main(void) | ||
{ | ||
/* data + recovery */ | ||
static uint8_t data[(DATA_SHARDS + RECOVERY_SHARDS) * SHARD_SIZE]; | ||
/* copy of data for comparison */ | ||
static uint8_t data_cmp[DATA_SHARDS * SHARD_SIZE]; | ||
/* pointer to shards */ | ||
static uint8_t *shards[DATA_SHARDS + RECOVERY_SHARDS]; | ||
/* map of missing shards */ | ||
static uint8_t marks[DATA_SHARDS + RECOVERY_SHARDS]; | ||
|
||
/* generate random data */ | ||
random_bytes(data, sizeof(data_cmp)); | ||
memcpy(data_cmp, data, sizeof(data_cmp)); | ||
|
||
/* set up shard pointers */ | ||
for (unsigned i = 0; i < ARRAY_SIZE(shards); ++i) { | ||
shards[i] = &data[i * SHARD_SIZE]; | ||
} | ||
|
||
puts("START"); | ||
reed_solomon_init(); | ||
rs_t *rs = reed_solomon_new(DATA_SHARDS, RECOVERY_SHARDS); | ||
if (!rs) { | ||
puts("failed to init codec"); | ||
return -1; | ||
} | ||
|
||
printf("total: %d shards (%d bytes)\n", ARRAY_SIZE(marks), sizeof(data)); | ||
|
||
/* generate parity shards */ | ||
reed_solomon_encode(rs, shards, ARRAY_SIZE(shards), SHARD_SIZE); | ||
|
||
/* delete up to N shards */ | ||
for (int i = 0; i < RECOVERY_SHARDS; i++) { | ||
int at = random_uint32_range(0, ARRAY_SIZE(shards)); | ||
printf("clear shard %d (%u byte)\n", at, SHARD_SIZE); | ||
memset(shards[at], 0, SHARD_SIZE); | ||
marks[at] = 1; | ||
} | ||
|
||
puts("reconstruct…"); | ||
if (reed_solomon_reconstruct(rs, shards, marks, ARRAY_SIZE(shards), SHARD_SIZE)) { | ||
puts("failed."); | ||
} else { | ||
puts("done."); | ||
} | ||
reed_solomon_release(rs); | ||
|
||
if (memcmp(data, data_cmp, sizeof(data_cmp))) { | ||
puts("FAILED"); | ||
} else { | ||
puts("SUCCESS"); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
from testrunner import run | ||
|
||
|
||
def testfunc(child): | ||
child.expect('START') | ||
child.expect('SUCCESS') | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(run(testfunc)) |