Skip to content

Commit

Permalink
ext_example updates (#47)
Browse files Browse the repository at this point in the history
* update extension tests
* add app/ext_example tests to CI
* add ZSV_CONFIG_DIR env var override
  • Loading branch information
liquidaty committed Jul 14, 2022
1 parent d873307 commit 7e48c93
Show file tree
Hide file tree
Showing 16 changed files with 561 additions and 276 deletions.
15 changes: 8 additions & 7 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,19 @@ MORE_OBJECTS=
NO_LTO=0

ifeq ($(DEBUG),1)
NO_LTO=1
DBG_SUBDIR+=dbg
else
DBG_SUBDIR+=rel
endif

ifeq ($(NO_LTO),1)
CFLAGS+= -fno-lto
else
CFLAGS+=${CFLAGS_LTO}
LDFLAGS_OPT+= ${LDFLAGS_OPT_LTO}
endif

NO_STDIN=
ifeq ($(NO_STDIN),1)
CFLAGS+= -DNO_STDIN
Expand Down Expand Up @@ -91,7 +99,6 @@ ifeq ($(DEBUG),0)
$(echo "No profiling set. To use PGO, compile with PGO=1, then run with data, then compile again with PGO=2")
endif
endif

else
CFLAGS += -g
endif
Expand Down Expand Up @@ -161,12 +168,6 @@ endif
CLI_OBJECTS=$(addprefix ${CLI_OBJ_PFX},$(addsuffix .o,${CLI_SOURCES}))

CFLAGS+=${CFLAGS_AUTO}
ifeq ($(NO_LTO),1)
CFLAGS+= -fno-lto
else
CFLAGS+=${CFLAGS_LTO}
LDFLAGS_OPT+= ${LDFLAGS_OPT_LTO}
endif

ifeq ($(VERBOSE),1)
CFLAGS+= ${CFLAGS_VECTORIZE_OPTIMIZED} ${CFLAGS_VECTORIZE_MISSED} ${CFLAGS_VECTORIZE_ALL}
Expand Down
2 changes: 1 addition & 1 deletion app/benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The following utilities were compared:
* Our test system shown in the above graph was a pre-M1 OSX MBA.
We also tested on Linux, BSD
and Windows. In each case, zsv was the fastest, but in some cases the margin
was smaller (e.g. 20%+ instead of 50% vs xsv on Win).
was smaller (e.g. 20%+ instead of 50% vs xsv on Win).

### Results in above graph (pre-M1 OSX MBA)

Expand Down
12 changes: 11 additions & 1 deletion app/builtin/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ static int main_help(int argc, const char *argv[]) {
"",
"Usage:",
" zsv version: display version info (and if applicable, extension info)",
#ifndef __EMSCRIPTEN__
" zsv (un)register [<extension_id>]: (un)register an extension",
" Registration info is saved in zsv.ini located in a directory determined as:",
" ZSV_CONFIG_DIR environment variable value, if set",
# if defined(_WIN32)
" LOCALAPPDATA environment variable value, if set",
" otherwise, C:\\temp",
#else
" otherwise, " PREFIX "/etc",
# endif
#endif
" zsv help [<command>]",
" zsv <command> <options> <arguments>: run a command on data (see below for details)",
" zsv <id>-<cmd> <options> <arguments>: invoke command 'cmd' of extension 'id'",
Expand Down Expand Up @@ -72,8 +82,8 @@ static int main_help(int argc, const char *argv[]) {
for(struct zsv_ext_command *cmd = ext->commands; cmd; cmd = cmd->next)
fprintf(f, " %s-%s%s%s\n", ext->id, cmd->id, cmd->help ? ": " : "", cmd->help ? cmd->help : "");
}
config_free(&config);
}
config_free(&config);
}
if(!printed_init)
fprintf(f, "\n(No extended commands)\n");
Expand Down
8 changes: 4 additions & 4 deletions app/builtin/license.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ static int main_license(int argc, const char *argv[]) {
(void)(argv);

fprintf(stderr, "Note: for third-party licenses & acknowledgements, run `zsv thirdparty`\n");
printf("\n==========================\n");
printf("\n====================================================\n");
printf("ZSV/lib license");
printf(" ");
printf("\n==========================\n");
printf("\n====================================================\n");

fwrite(zsv_license_text_MIT, 1, strlen(zsv_license_text_MIT), stdout);

struct cli_config config;
if(!config_init(&config, 0, 1, 0)) {
for(struct zsv_ext *ext = config.extensions; ext; ext = ext->next) {
printf("\n==========================\n");
printf("\n====================================================\n");
printf("License for extension '%s'", ext->id);
printf("\n==========================\n");
printf("\n====================================================\n");
if(ext->license && *ext->license) {
size_t len = strlen(ext->license);
fwrite(ext->license, 1, len, stdout);
Expand Down
57 changes: 32 additions & 25 deletions app/ext_example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ else
endif
CFLAGS+= ${CFLAGS_PIC}

ifeq ($(ZSV_EXTRAS),1)
CFLAGS+= -DZSV_EXTRAS
endif

DEBUG=0
ifeq ($(DEBUG),0)
Expand Down Expand Up @@ -94,6 +97,10 @@ ${INSTALLED_EXTENSION}: ${TARGET}
cp -p $< $@
endif

CLI=${BUILD_DIR}/bin/cli

RUN_CLI=ZSV_CONFIG_DIR=/tmp ${CLI}

${BUILD_DIR}/bin/cli:
(cd .. && make CC=${CC} CONFIGFILE=${CONFIGFILEPATH} DEBUG=${DEBUG} ${BUILD_DIR}/bin/cli)

Expand All @@ -102,43 +109,43 @@ ${BUILD_DIR}/objs/utils/%.o:

test: test-1 test-2 test-3 test-4 test-5 test-thirdparty

test-1: test-%: ${BUILD_DIR}/bin/cli ${TARGET}
@${BUILD_DIR}/bin/cli my-echo < ${THIS_LIB_BASE}/data/quoted.csv > /tmp/zsvext-$@.out
test-1: test-%: ${CLI} ${TARGET}
@${RUN_CLI} my-echo < ${THIS_LIB_BASE}/data/quoted.csv > /tmp/zsvext-$@.out
@cmp /tmp/zsvext-$@.out test/expected/zsvext-$@.out && ${TEST_PASS} || ${TEST_FAIL}

test-2: test-%: ${BUILD_DIR}/bin/cli ${TARGET}
@${BUILD_DIR}/bin/cli my-echo -t < ${THIS_LIB_BASE}/data/hi.txt > /tmp/zsvext-$@.out
test-2: test-%: ${CLI} ${TARGET}
@${RUN_CLI} my-echo -t < ${THIS_LIB_BASE}/data/hi.txt > /tmp/zsvext-$@.out
@cmp /tmp/zsvext-$@.out test/expected/zsvext-$@.out && ${TEST_PASS} || ${TEST_FAIL}

test-3: test-%: ${BUILD_DIR}/bin/cli ${TARGET}
test-3: test-%: ${CLI} ${TARGET}
@rm -f /tmp/zsvext-$@.out
@${BUILD_DIR}/bin/cli unregister my 2>/dev/null 1>/dev/null || [ 1==1 ]
@${BUILD_DIR}/bin/cli register my 2>&1 | grep -v [.]so >> /tmp/zsvext-$@.out || [ 1==1 ]
@${BUILD_DIR}/bin/cli unregister my 2>&1 | grep -v [.]so >> /tmp/zsvext-$@.out || [ 1==1 ]
@${BUILD_DIR}/bin/cli unregister my 2>&1 | grep -v [.]so >> /tmp/zsvext-$@.out || [ 1==1 ]
@${BUILD_DIR}/bin/cli help 2>&1 | grep -v [.]so >> /tmp/zsvext-$@.out || [ 1==1 ]
@${BUILD_DIR}/bin/cli register my 2>&1 | grep -v [.]so >> /tmp/zsvext-$@.out || [ 1==1 ]
@${BUILD_DIR}/bin/cli help 2>&1 | grep -v [.]so >> /tmp/zsvext-$@.out || [ 1==1 ]
@${RUN_CLI} unregister my 2>/dev/null 1>/dev/null || [ 1==1 ]
@${RUN_CLI} register my 2>&1 | grep -v [.]so >> /tmp/zsvext-$@.out || [ 1==1 ]
@${RUN_CLI} unregister my 2>&1 | grep -v [.]so >> /tmp/zsvext-$@.out || [ 1==1 ]
@${RUN_CLI} unregister my 2>&1 | grep -v [.]so >> /tmp/zsvext-$@.out || [ 1==1 ]
@${RUN_CLI} help 2>&1 | grep -v [.]so >> /tmp/zsvext-$@.out || [ 1==1 ]
@${RUN_CLI} register my 2>&1 | grep -v [.]so >> /tmp/zsvext-$@.out || [ 1==1 ]
@${RUN_CLI} help 2>&1 | grep -v [.]so >> /tmp/zsvext-$@.out || [ 1==1 ]
@cmp /tmp/zsvext-$@.out 2>&1 test/expected/zsvext-$@.out && ${TEST_PASS} || ${TEST_FAIL}

test-4: test-%: ${BUILD_DIR}/bin/cli ${TARGET}
@${BUILD_DIR}/bin/cli unregister my 2>/dev/null 1>/dev/null || [ 1==1 ]
@${BUILD_DIR}/bin/cli license > /tmp/zsvext-$@.out 2>> /tmp/zsvext-$@.err
@${BUILD_DIR}/bin/cli register my 2>/dev/null 1>/dev/null
@${BUILD_DIR}/bin/cli license >> /tmp/zsvext-$@.out 2> /tmp/zsvext-$@.err
test-4: test-%: ${CLI} ${TARGET}
@${RUN_CLI} unregister my 2>/dev/null 1>/dev/null || [ 1==1 ]
@${RUN_CLI} license > /tmp/zsvext-$@.out 2>> /tmp/zsvext-$@.err
@${RUN_CLI} register my 2>/dev/null 1>/dev/null
@${RUN_CLI} license >> /tmp/zsvext-$@.out 2> /tmp/zsvext-$@.err
@cmp /tmp/zsvext-$@.out test/expected/zsvext-$@.out && ${TEST_PASS} || ${TEST_FAIL}
@cmp /tmp/zsvext-$@.err test/expected/zsvext-$@.err && ${TEST_PASS} || ${TEST_FAIL}

test-5: test-%: ${BUILD_DIR}/bin/cli ${TARGET}
@${BUILD_DIR}/bin/cli my-count newline.csv 2>/dev/null > /tmp/zsvext-$@.out
@${BUILD_DIR}/bin/cli my-count -q newline.csv 2>/dev/null >> /tmp/zsvext-$@.out
test-5: test-%:${TARGET}
@${RUN_CLI} my-count newline.csv 2>/dev/null > /tmp/zsvext-$@.out
@${RUN_CLI} my-count -q newline.csv 2>/dev/null >> /tmp/zsvext-$@.out
@cmp /tmp/zsvext-$@.out test/expected/zsvext-$@.out && ${TEST_PASS} || ${TEST_FAIL}

test-thirdparty: test-%: ${BUILD_DIR}/bin/cli ${TARGET}
@${BUILD_DIR}/bin/cli unregister my 2>/dev/null 1>/dev/null || [ 1==1 ]
@${BUILD_DIR}/bin/cli thirdparty > /tmp/zsvext-$@.out
@${BUILD_DIR}/bin/cli register my 2>/dev/null 1>/dev/null
@${BUILD_DIR}/bin/cli thirdparty >> /tmp/zsvext-$@.out
test-thirdparty: test-%: ${CLI} ${TARGET}
@${RUN_CLI} unregister my 2>/dev/null 1>/dev/null || [ 1==1 ]
@${RUN_CLI} thirdparty > /tmp/zsvext-$@.out
@${RUN_CLI} register my 2>/dev/null 1>/dev/null
@${RUN_CLI} thirdparty >> /tmp/zsvext-$@.out
@cmp /tmp/zsvext-$@.out test/expected/zsvext-$@.out && ${TEST_PASS} || ${TEST_FAIL}

clean:
Expand Down
Loading

0 comments on commit 7e48c93

Please sign in to comment.