hmmlib2: hmmldump -x option for extra output, afl fuzz testing
This commit is contained in:
parent
1993e9f1dd
commit
678be54e51
|
@ -0,0 +1,5 @@
|
|||
/utils/hmmldump
|
||||
/utils/fuzz/fuzz.gcno
|
||||
/utils/fuzz/fuzz.gcda
|
||||
/utils/fuzz/output
|
||||
/utils/fuzz/fuzz
|
|
@ -1,6 +1,8 @@
|
|||
#define HMMLIB_IMPLEMENTATION
|
||||
#include "hmmlib.h"
|
||||
#include "stb_sb.h"
|
||||
#include <stdbool.h>
|
||||
#include <getopt.h>
|
||||
|
||||
typedef struct {
|
||||
char* text;
|
||||
|
@ -17,7 +19,7 @@ static Index* index_find(Index* base, const char* text)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void hmml_dump(HMML_Output* hmml)
|
||||
void hmml_dump(HMML_Output* hmml, bool extra)
|
||||
{
|
||||
if(!hmml){
|
||||
puts("(null)");
|
||||
|
@ -29,6 +31,27 @@ void hmml_dump(HMML_Output* hmml)
|
|||
return;
|
||||
}
|
||||
|
||||
if(extra) {
|
||||
puts("Metadata:");
|
||||
static const char* meta[] = { "member", "stream_platform", "stream_username", "project", "title", "vod_platform", "id", "output", "template", "medium" };
|
||||
for(size_t i = 0; i < countof(meta); ++i) {
|
||||
const char* value = ((char**)&hmml->metadata)[i];
|
||||
printf(" %s = %s\n", meta[i], value);
|
||||
}
|
||||
|
||||
puts(" Credits:");
|
||||
for(size_t i = 0; i < hmml->metadata.credit_count; ++i) {
|
||||
HMML_Credit* c = hmml->metadata.credits + i;
|
||||
printf(" %s [%s]\n", c->name, c->role);
|
||||
}
|
||||
|
||||
puts(" Custom:");
|
||||
for(size_t i = 0; i < hmml->metadata.custom_count; ++i) {
|
||||
HMML_VideoCustomMetaData* m = hmml->metadata.custom + i;
|
||||
printf(" %s = %s\n", m->key, m->value);
|
||||
}
|
||||
}
|
||||
|
||||
puts("Annotations:");
|
||||
for(size_t i = 0; i < hmml->annotation_count; ++i){
|
||||
HMML_Annotation* a = hmml->annotations + i;
|
||||
|
@ -159,12 +182,35 @@ void hmml_dump(HMML_Output* hmml)
|
|||
}
|
||||
}
|
||||
|
||||
void usage(char* argv0, FILE* out)
|
||||
{
|
||||
fprintf(out, "Usage: %s [-bx] [file]\n", argv0);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 2) {
|
||||
fprintf(stderr, "Usage: %s [file]\n", argv[0]);
|
||||
bool dump_extra = false;
|
||||
bool breakpoint = false;
|
||||
int opt;
|
||||
|
||||
while((opt = getopt(argc, argv, "bx")) != -1) {
|
||||
if(opt == 'x') {
|
||||
dump_extra = true;
|
||||
} else if(opt == 'b') {
|
||||
breakpoint = true;
|
||||
} else {
|
||||
usage(argv[0], stderr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(optind >= argc){
|
||||
usage(argv[0], stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
argc -= (optind-1);
|
||||
argv += (optind-1);
|
||||
|
||||
FILE* f = fopen(argv[1], "r");
|
||||
if(!f) {
|
||||
|
@ -185,8 +231,11 @@ int main(int argc, char** argv)
|
|||
HMML_Output out = hmml_parse(mem);
|
||||
free(mem);
|
||||
|
||||
// asm("int3");
|
||||
hmml_dump(&out);
|
||||
if(breakpoint) {
|
||||
asm("int3");
|
||||
}
|
||||
|
||||
hmml_dump(&out, dump_extra);
|
||||
|
||||
hmml_free(&out);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
fuzz: fuzz.c ../../hmmlib.h
|
||||
afl-gcc -I../.. -g -D_GNU_SOURCE -fprofile-arcs -ftest-coverage $< -o $@
|
||||
|
||||
run: fuzz | output
|
||||
afl-fuzz -i tests -o output ./$<
|
||||
|
||||
cov: fuzz | output
|
||||
afl-cov -d output --coverage-cmd 'cat AFL_FILE | ./fuzz' --code-dir . --enable-branch-coverage --overwrite
|
||||
|
||||
output:
|
||||
mkdir -p $@
|
||||
|
||||
clean:
|
||||
rm -rf fuzz fuzz.gcno fuzz.gcda output
|
||||
|
||||
.PHONY: run cov clean
|
|
@ -0,0 +1,20 @@
|
|||
#define HMMLIB_IMPLEMENTATION
|
||||
#include "hmmlib.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
char* mem = NULL;
|
||||
size_t size = 0;
|
||||
char buf[BUFSIZ];
|
||||
|
||||
while(fgets(buf, BUFSIZ, stdin)) {
|
||||
size_t n = strlen(buf) + 1;
|
||||
mem = realloc(mem, size + n);
|
||||
memcpy(mem + size, buf, n);
|
||||
size += n - 1;
|
||||
}
|
||||
|
||||
HMML_Output out = hmml_parse(mem);
|
||||
free(mem);
|
||||
hmml_free(&out);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
[video member=nothings credit="inso:programmer" annotator=Miblo]
|
||||
[2:01][Recap and update the TODO list]
|
||||
[38:58][Continue implementing parse_tag()][:parsing :test]
|
||||
[41:40][@miblo][Ohhh, right. Yeah, the \[video\] and \[/video\] tags are the only :ones that [:have a s d f] that open-close format. All the [~other] [@tags abc] are "single" tags]
|
||||
[45:17][Enable parse_tag() to tokenise the \[video\] node][:parsing][quote bob 1]
|
||||
[3:42:11][@miblo][@nothings2: That's fine, yeah! They are also in: [ref
|
||||
site="GitLab: Annotation-Pushers / Annotation-Game"
|
||||
page="projects/nothings/obbg"
|
||||
url=http://git.handmadedev.org/Annotation-Pushers/Annotation-Game/tree/master/projects/nothings/obbg]]
|
||||
[3:50:44][Take a break][quote 5]
|
||||
[/video]
|
|
@ -0,0 +1,3 @@
|
|||
[video credit=inso:programmer]
|
||||
[2:01][Recap and :update the ~TODO @list]
|
||||
[/video]
|
Loading…
Reference in New Issue