Skip to content

Commit

Permalink
build, test: detect memory leaks in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Dec 12, 2022
1 parent 55df6af commit 60bfe9f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/memory-sanitizer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Memory Sanitizer

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Ubuntu Install Deps
run: sudo apt-get update && sudo apt-get install -y libunbound-dev

- name: Build
run: ./autogen.sh && ./configure --with-network=regtest --with-sanitizers=address && make

- name: Unit Tests
run: ./test_hnsd

- name: Setup Integration
uses: actions/[email protected]
with:
node-version: 18

- name: Integration Tests
working-directory: ./integration
run: |
npm install
npm run test
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AUTOMAKE_OPTIONS = foreign
CFLAGS = -Wall -Wno-unused-function -std=gnu11 -O2
LDFLAGS =
CFLAGS = -Wall -Wno-unused-function -std=gnu11 -O2 $(SANITIZER_FLAGS)
LDFLAGS = $(SANITIZER_FLAGS)

SUBDIRS = uv

Expand Down
9 changes: 9 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ AC_ARG_WITH([unbound],
[libunbound_path=$withval],
[libunbound_path=yes])

AC_ARG_WITH([sanitizers],
[AS_HELP_STRING(
[--with-sanitizers]
[comma separated list of extra sanitizers to build with (default is none)]
)],
[SANITIZER_FLAGS="-g -fsanitize=$withval"])

AC_SUBST(SANITIZER_FLAGS, ${SANITIZER_FLAGS})

AC_CHECK_TYPES([__int128])

AC_MSG_CHECKING([for __builtin_expect])
Expand Down
21 changes: 18 additions & 3 deletions integration/test-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class TestUtil {
this.hnsdHeight = 0;
this.hnsdArgsBase = ['-s', '127.0.0.1:10000'];
this.hnsdArgs = this.hnsdArgsBase;
this.message = '';
}

extraArgs(args) {
Expand Down Expand Up @@ -93,21 +94,35 @@ class TestUtil {
}

async close() {
this.closeHNSD();
await this.node.close();
this.closeHNSD();
}

async openHNSD() {
return new Promise((resolve, reject) => {
this.hnsd = spawn(
path.join(__dirname, '..', 'hnsd'),
this.hnsdArgs,
{stdio: 'ignore'}
{stdio: ['ignore', 'ignore', 'pipe']}
);

this.hnsd.on('spawn', () => resolve());
this.hnsd.on('error', () => reject());
this.hnsd.on('close', this.crash);

this.message = '';
this.hnsd.stderr.on('data', (data) => {
this.message += data.toString('ascii');
});
this.hnsd.stderr.on('end', (data) => {
if (!this.message.length)
return;

const msg = this.message;
this.message = '';
console.log(msg);
throw new Error(msg);
});
});
}

Expand All @@ -121,7 +136,7 @@ class TestUtil {

this.hnsd.removeListener('close', this.crash);

this.hnsd.kill('SIGKILL');
this.hnsd.kill('SIGINT');
this.hnsd = null;
}

Expand Down

0 comments on commit 60bfe9f

Please sign in to comment.