Skip to content

Commit

Permalink
Fix up tools and tests and site update
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Sep 19, 2024
1 parent f9b4b9b commit c8b2987
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="([^/\\\\]*)((g?cc)|([gc]\+\+)|(clang))" prefer-non-shared="true"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="533368308517884254" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
Expand Down
21 changes: 14 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,33 @@ else
$(info WARNING! Doxygen is not available. Will skip 'dox' target)
endif


# Link against thread lib
LDFLAGS += -pthread

export

# Build everything...
.PHONY: all
all: shared static $(DOC_TARGETS) check
all: shared static tools $(DOC_TARGETS) check

# Shared libraries (versioned and unversioned)
.PHONY: shared
shared: $(LIB)/libsmax.so
shared: $(LIB)/libsmax.so

# Legacy static libraries (locally built)
.PHONY: static
static: $(LIB)/libsmax.a

# Run regression tests
.PHONY: test
test:
make -C test
test: SRC := tests/src
test: shared static
make -f test.mk

.PHONY: tools
tools: SRC := tools/src
tools: shared static
make -f tools.mk

# Remove intermediates
.PHONY: clean
Expand All @@ -59,7 +66,6 @@ clean:
distclean: clean
rm -f Doxyfile.local $(LIB)/libsmax.so* $(LIB)/libsmax.a


# ----------------------------------------------------------------------------
# The nitty-gritty stuff below
# ----------------------------------------------------------------------------
Expand All @@ -79,6 +85,7 @@ $(LIB)/libsmax.so.$(SO_VERSION): $(SOURCES)
# Static library
$(LIB)/libsmax.a: $(OBJECTS) | $(LIB) Makefile


README-smax.md: README.md
LINE=`sed -n '/\# /{=;q;}' $<` && tail -n +$$((LINE+2)) $< > $@

Expand All @@ -105,6 +112,7 @@ help:
@echo
@echo " shared Builds the shared 'libsmax.so' (linked to versioned)."
@echo " static Builds the static 'lib/libsmax.a' library."
@echo " tools Command line tools: 'bin/smaxValue' and 'bin/smaxWrite'."
@echo " local-dox Compiles local HTML API documentation using 'doxygen'."
@echo " check Performs static analysis with 'cppcheck'."
@echo " all All of the above."
Expand All @@ -121,4 +129,3 @@ Makefile: config.mk build.mk

include build.mk


27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Last Updated: 18 September 2024
- [Introduction](#introduction)
- [Prerequisites](#prerequisites)
- [Building the SMA-X C library](#building)
- [Command-line tools](#command-line-tools)
- [Initial configuration](#configuration)
- [Connecting to / disconnecting from SMA-X](#connecting)
- [Sharing and pulling data](#sharing-and-pulling)
Expand Down Expand Up @@ -111,6 +112,12 @@ prior to invoking `make`. The following build variables can be configured:
automatically.

- `LDFLAGS`: Linker flags (default is `-lm`). Note, `-lredisx -lxchange` will be added automatically.

- `THREADS`: Linker flags for the __pthread__ library. It will be added to `LDFLAGS` automatically. (default:
`-pthread`)

- `RTLIB`: Linker flags fo linking against a realtime (if necessary). It will be added to `LDFLAGS`
automatically. (default: empty)

- `BUILD_MODE`: You can set it to `debug` to enable debugging features: it will initialize the global `xDebug`
variable to `TRUE` and add `-g` to `CFLAGS`.
Expand All @@ -124,6 +131,26 @@ desired `make` target(s). (You can use `make help` to get a summary of the avail

------------------------------------------------------------------------------

<a name="command-line-tools"></a>
## Command-line tools

The __smax-clib__ library provides two basic command-line tools:

- `smaxValue` -- for exploring the contents of SMA-X, including associated metadata, and
- `smaxWrite` -- for putting data into SMA-X from the shell.

The tools can be compiled with `make tools`. Both tools can be run with the `--help` option for a simple help screen on
usage. E.g.:

```bash
$ smaxValue --help
```

These command-line tools provide a simple means to interact with SMA-X from the shell or a scripting language, such
as `bash`, or `perl` (also `python` though we recommend to use the native
[Smithsonian/smax-python](https://github.com/Smithsonian/smax-python) library instead).

------------------------------------------------------------------------------

<a name="configuration"></a>
## Initial configuration
Expand Down
6 changes: 5 additions & 1 deletion build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ $(LIB)/lib%.so:
# Static library: *.a
$(LIB)/%.a:
ar -rc $@ $^
ranlib $@
ranlib $@

# Simple binaries
$(BIN)/%: $(OBJ)/%.o | $(BIN)
$(CC) -o $@ $^ $(LDFLAGS)

# Create sub-directories for build targets
dep $(OBJ) $(LIB) $(BIN) apidoc:
Expand Down
14 changes: 10 additions & 4 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,30 @@ CFLAGS ?= -Os -Wall -std=c99
#CFLAGS += -Wextra

# Link against math libs (for e.g. isnan())
LDFLAGS ?= -lm
LDFLAGS ?= -lm

# Link flags to use for threading with pthread
THREADS ?= -pthread

# Runtime libraries to link against (if any)
#RTLIB ?= -lrt

# Compile and link against a specific redisx library (if defined)
ifdef REDISX
CPPFLAGS += -I$(REDISX)/include
LDFLAGS += -L$(REDISX)/lib
LD_LIBRARY_PATH = $(REDISX)/lib:$(LD_LIBRARY_PATH)
LD_LIBRARY_PATH := $(REDISX)/lib:$(LD_LIBRARY_PATH)
endif

# Compile and link against a specific xchange library (if defined)
ifdef XCHANGE
CPPFLAGS += -I$(XCHANGE)/include
LDFLAGS += -L$(XCHANGE)/lib
LD_LIBRARY_PATH = $(XCHANGE)/lib:$(LD_LIBRARY_PATH)
LD_LIBRARY_PATH := $(XCHANGE)/lib:$(LD_LIBRARY_PATH)
endif

# Always link against the xchange lib.
LDFLAGS += -lredisx -lxchange
LDFLAGS += -lredisx -lxchange $(RTLIB) $(THREADS)

# cppcheck options for 'check' target
CHECKOPTS ?= --enable=performance,warning,portability,style --language=c \
Expand Down
21 changes: 21 additions & 0 deletions test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Load the common Makefile definitions...
include config.mk

CFLAGS += -g
LDFLAGS += -L$(LIB) -lsmax

LD_LIBRARY_PATH := $(LIB):$(LD_LIBRARY_PATH)


TESTS = $(BIN)/simpleIntTest $(BIN)/simpleIntsTest $(BIN)/structTest $(BIN)/queueTest $(BIN)/lazyTest \
$(BIN)/waitTest $(BIN)/resilientTest

# Top level make targets...
all: $(TESTS)


$(BIN)/%: $(OBJ)/%.o | $(BIN)
$(CC) -o $@ $^ $(LDFLAGS)

# Standard generic rules and targets...
include build.mk
41 changes: 0 additions & 41 deletions tests/Makefile

This file was deleted.

6 changes: 5 additions & 1 deletion tests/src/lazyTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* to smaxLazyPull(), and then only when an update notification is received for the lazy value.
*/

#define _POSIX_C_SOURCE 199309L ///< for nanosleep()

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -97,11 +98,14 @@ int main(int argc, const char *argv[]) {

// Give the PollingThread a bit of time to detect the change and exit normally
while(--timeoutLoops >= 0) {
struct timespec interval = { 0, 10000000 }; // Check every 10ms

if(gotUpdate) {
printf("lazy: OK (%d queries, %d update[s])\n", nQueries, nUpdates);
exit(0);
}
usleep(10000); // Check every 10ms

nanosleep(&interval, NULL);
}

// Once we are done with a set of lazy pulling, we can flush all lazy caches
Expand Down
5 changes: 3 additions & 2 deletions tests/src/queueTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ struct {

// This is an example callback function that we want to be called when
// out data has been queued for high-throughput pulls from SMA-X...
static void checkPull(char *arg) {
static void checkPull(void *arg) {
char *str = (char *) arg;

// Check the argument that was passed to us...
if(strcmp(arg, CALLBACKARG)) {
if(strcmp(str, CALLBACKARG)) {
fprintf(stderr, "ERROR! callback: Unexpected callback argument.\n");
exit(-1);
}
Expand Down
6 changes: 5 additions & 1 deletion tests/src/waitTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* to smaxLazyPull(), and then only when an update notification is received for the lazy value.
*/

#define _POSIX_C_SOURCE 199309L ///< for nanosleep()

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -93,11 +94,14 @@ int main(int argc, const char *argv[]) {

// Give the WaitingThread a bit of time to detect the change and exit normally
while(--timeoutLoops >= 0) {
struct timespec interval = { 0, 10000000 }; // Check every 10ms

if(gotUpdate) {
printf("wait: OK\n");
exit(0);
}
usleep(10000); // Check every 10ms

nanosleep(&interval, NULL); // Check every 10ms
}

// If we go this far, then the polling thread did not get the update
Expand Down
15 changes: 15 additions & 0 deletions tools.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Load the common Makefile definitions...
include config.mk

LDFLAGS += -L$(LIB) -lsmax
LD_LIBRARY_PATH := $(LIB):$(LD_LIBRARY_PATH)

# Top level make targets...
all: $(BIN)/smaxValue $(BIN)/smaxWrite

# Standard generic rules and targets...
include build.mk




29 changes: 0 additions & 29 deletions tools/Makefile

This file was deleted.

4 changes: 2 additions & 2 deletions tools/src/smaxValue.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static int printValue(const char *group, const char *key) {
strftime(date, 100, "%Y-%m-%d %H:%M:%S", ts);

printf("\n");
printf(MAG " #" BLU " Type: " RST "%s\n", xStringType(meta.storeType));
printf(MAG " #" BLU " Type: " RST "%s\n", smaxStringType(meta.storeType));
printf(MAG " #" BLU " Size: " RST "%s\n", dims);
printf(MAG " #" BLU " Origin: " RST "%s\n", meta.origin[0] ? meta.origin : RED "<null>" RST);
printf(MAG " #" BLU " Time: " RST "%s (" GRN "%s.%03ld" CYN " UTC" RST ")\n", TS, date, (meta.timestamp.tv_nsec / 1000000));
Expand Down Expand Up @@ -217,7 +217,7 @@ static void setOption(char *argv[], int *next) {
if(!strcmp(option, "m") || !strcmp(option, "-meta")) showMeta = TRUE;
else if(!strcmp(option, "e") || !strcmp(option, "-errors")) printErrors = TRUE;
else if(!strcmp(option, "l") || !strcmp(option, "-list")) showList = TRUE;
else if(!strcmp(option, "t") || !strcmp(option, "-type")) type = xTypeForString(argv[(*next)++]);
else if(!strcmp(option, "t") || !strcmp(option, "-type")) type = smaxTypeForString(argv[(*next)++]);
else if(!strcmp(option, "n") || !strcmp(option, "-count")) count = atoi(argv[(*next)++]);
else if(!strcmp(option, "s") || !strcmp(option, "-server")) host = argv[(*next)++];
else fprintf(stderr, "WARNING! no option: -%s\n", option);
Expand Down
2 changes: 1 addition & 1 deletion tools/src/smaxWrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void setOption(char *argv[], int *next) {

if(!strcmp(option, "t") || !strcmp(option, "-type")) {
sType = argv[(*next)++];
f.type = xTypeForString(sType);
f.type = smaxTypeForString(sType);
if(f.type == X_UNKNOWN || f.type == X_STRUCT) {
fprintf(stderr, "ERROR! Invalid type: %s\n", sType);
exit(1);
Expand Down

0 comments on commit c8b2987

Please sign in to comment.