-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
91 changed files
with
3,295 additions
and
2,189 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
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
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
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
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
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,2 @@ | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
/ascii85-bandwidth |
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,28 @@ | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
# | ||
# Copyright(c) 2024 John Sanpe <[email protected]> | ||
# | ||
|
||
add_executable(ascii85-bandwidth bandwidth.c) | ||
target_link_libraries(ascii85-bandwidth bfdev) | ||
add_test(ascii85-bandwidth ascii85-bandwidth) | ||
|
||
add_executable(ascii85 utils.c) | ||
target_link_libraries(ascii85 bfdev) | ||
add_test(ascii85 ascii85 "helloworld") | ||
|
||
if(${CMAKE_PROJECT_NAME} STREQUAL "bfdev") | ||
install(FILES | ||
bandwidth.c | ||
utils.c | ||
DESTINATION | ||
${CMAKE_INSTALL_DOCDIR}/examples/ascii85 | ||
) | ||
|
||
install(TARGETS | ||
ascii85 | ||
ascii85-bandwidth | ||
DESTINATION | ||
${CMAKE_INSTALL_DOCDIR}/bin | ||
) | ||
endif() |
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,69 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* Copyright(c) 2024 John Sanpe <[email protected]> | ||
*/ | ||
|
||
#define MODULE_NAME "ascii85-bandwidth" | ||
#define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <bfdev/ascii85.h> | ||
#include <bfdev/crc.h> | ||
#include <bfdev/log.h> | ||
#include <bfdev/size.h> | ||
#include "../time.h" | ||
|
||
#define TEST_SIZE BFDEV_SZ_1MiB | ||
#define TEST_LOOP 3 | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
unsigned int count, loop; | ||
uint8_t *dbuff, *sbuff; | ||
size_t dlen, slen, index; | ||
uint32_t cksum, check; | ||
|
||
slen = bfdev_ascii85_encode_length(TEST_SIZE); | ||
sbuff = malloc(slen); | ||
if (!sbuff) | ||
return 1; | ||
|
||
dlen = bfdev_ascii85_decode_length(slen); | ||
dbuff = malloc(dlen); | ||
if (!dbuff) | ||
return 1; | ||
|
||
srand(time(NULL)); | ||
for (index = 0; index < dlen; ++index) | ||
dbuff[index] = (uint8_t)rand(); | ||
|
||
cksum = bfdev_crc32(dbuff, dlen, (uint32_t)~0UL); | ||
bfdev_log_info("start checksum: %#010x\n", cksum); | ||
|
||
for (count = 0; count < TEST_LOOP; ++count) { | ||
EXAMPLE_TIME_LOOP(&loop, 1000, | ||
bfdev_ascii85_encode(sbuff, dbuff, &slen, dlen); | ||
0; | ||
); | ||
bfdev_log_info("encode bandwidth %u: %uMiB/s\n", count, loop); | ||
|
||
EXAMPLE_TIME_LOOP(&loop, 1000, | ||
bfdev_ascii85_decode(dbuff, sbuff, &dlen, slen); | ||
0; | ||
); | ||
bfdev_log_info("decode bandwidth %u: %uMiB/s\n", count, loop); | ||
} | ||
|
||
check = bfdev_crc32(dbuff, dlen, (uint32_t)~0UL); | ||
if (cksum != check) { | ||
bfdev_log_err("verification failed\n"); | ||
return 1; | ||
} | ||
bfdev_log_info("verification pass\n"); | ||
|
||
free(sbuff); | ||
free(dbuff); | ||
|
||
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,87 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* Copyright(c) 2024 John Sanpe <[email protected]> | ||
*/ | ||
|
||
#define MODULE_NAME "bfdev-ascii85" | ||
#define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <bfdev/log.h> | ||
#include <bfdev/errname.h> | ||
#include <bfdev/ascii85.h> | ||
|
||
int | ||
main(int argc, const char *argv[]) | ||
{ | ||
unsigned int index; | ||
bool decode; | ||
int retval; | ||
|
||
decode = false; | ||
for (index = 1; index < argc; ++index) { | ||
const char *para; | ||
|
||
para = argv[index]; | ||
if (para[0] != '-') | ||
break; | ||
|
||
switch (para[1]) { | ||
case 'd': | ||
decode = true; | ||
break; | ||
|
||
case 'h': default: | ||
goto usage; | ||
} | ||
} | ||
|
||
if (index == argc) | ||
goto usage; | ||
|
||
do { | ||
size_t len1, len2, len3; | ||
const char *data; | ||
char *buff; | ||
|
||
data = argv[index]; | ||
len1 = strlen(data); | ||
|
||
if (decode) | ||
len2 = bfdev_ascii85_decode_length(len1); | ||
else | ||
len2 = bfdev_ascii85_encode_length(len1); | ||
|
||
buff = malloc(len2); | ||
if (!buff) { | ||
bfdev_log_err("Out of memory.\n"); | ||
return 1; | ||
} | ||
|
||
if (!decode) | ||
bfdev_ascii85_encode(buff, data, &len3, len1); | ||
else { | ||
retval = bfdev_ascii85_decode(buff, data, &len3, len1); | ||
if (retval) { | ||
const char *ername, *infop; | ||
|
||
ername = bfdev_errname(retval, &infop); | ||
bfdev_log_err("Decode error: %s (%s).\n", ername, infop); | ||
|
||
return retval; | ||
} | ||
} | ||
|
||
fwrite(buff, 1, len3, stdout); | ||
fputc('\n', stdout); | ||
free(buff); | ||
} while (++index < argc); | ||
|
||
return 0; | ||
|
||
usage: | ||
bfdev_log_err("Usage: %s [-d] data ...\n", argv[0]); | ||
return 1; | ||
} |
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
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
Oops, something went wrong.