Skip to content

Commit

Permalink
Check if valgrind is operational
Browse files Browse the repository at this point in the history
  • Loading branch information
nsauzede committed Oct 17, 2023
1 parent 5c4ae7e commit 9935c48
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/vade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt install --quiet -y make gcc python3 bash valgrind nasm
run: sudo apt update && sudo apt install --quiet -y make gcc python3 bash valgrind nasm
- name: Build and test
run: bin/vade clean test
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ ifeq ($(CC),$(CLANG))
VALGRIND:=
endif

ifeq (, $(shell which $(VALGRIND) 2>/dev/null))
ifneq (,$(VALGRIND))
# Check if valgrind is operational (eg: not missing debuginfo etc..)
ifneq (0, $(shell ($(VALGRIND) /bin/true 2>/dev/null ; echo $$?)))
#$(error "NOT HAVE VALGRIND ($(VALGRIND))")
RUN:=
RUNTEST:=RUN
Expand All @@ -71,6 +73,8 @@ else
VGRUN:=$(VALGRIND) $(VGOPTS)
RUNTEST:=VGRUN
endif
endif

RUNPYTEST:=RUNPY

ifeq (, $(shell which $(GCOV) 2>/dev/null))
Expand Down
40 changes: 40 additions & 0 deletions vade/src/open_close/open_close.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "open_close.h"
#include <stdlib.h>
#include <string.h>

printer_t *printer() {
printer_t *p = calloc(1, sizeof(printer_t));
p->text = calloc(1, 1);
}
void printer_free(printer_t *p) {
if (p) {
free(p->text);
free(p);
}
}
void printer_print(printer_t *p, char *s) {
p->text = realloc(p->text, strlen(p->text) + strlen(s) + 1);
strcat(p->text, s);
}

#include "test/test.h"
TEST_F(open_close, Printer_001_empty) {
printer_t *p = printer();
EXPECT_STREQ("", p->text);
printer_free(p);
}

TEST_F(open_close, Printer_002_one_print) {
printer_t *p = printer();
printer_print(p, "hello");
EXPECT_STREQ("hello", p->text);
printer_free(p);
}

TEST_F(open_close, Printer_003_two_prints) {
printer_t *p = printer();
printer_print(p, "hello");
printer_print(p, " world!\n");
EXPECT_STREQ("hello world!\n", p->text);
printer_free(p);
}
5 changes: 5 additions & 0 deletions vade/src/open_close/open_close.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
typedef struct {
char *text;
} printer_t;
extern printer_t *printer();
extern void printer_print(printer_t *p, char *s);

0 comments on commit 9935c48

Please sign in to comment.