add valgrind check

This commit is contained in:
Philipp Moritz
2016-10-05 18:07:08 -07:00
parent a3e01c8a45
commit e8e4aa6d8e
3 changed files with 68 additions and 6 deletions
+13
View File
@@ -29,6 +29,19 @@ matrix:
install: []
script:
- .travis/check-git-clang-format-output.sh
- os: linux
dist: trusty
python: "2.7"
env: VALGRIND=1
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq valgrind
script:
- cd common
- make test
- cd ..
- source setup-env.sh
- python test/test.py valgrind
install:
- make
+30 -3
View File
@@ -1,4 +1,5 @@
#include <inttypes.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
@@ -24,6 +25,9 @@ UT_icd task_ptr_icd = {sizeof(task_instance *), NULL, NULL, NULL};
UT_icd worker_icd = {sizeof(available_worker), NULL, NULL, NULL};
struct local_scheduler_state {
/* The local scheduler event loop. */
event_loop *loop;
/* The handle to the database. */
db_handle *db;
/** This is an array of pointers to tasks that are waiting to be scheduled. */
UT_array *task_queue;
@@ -35,6 +39,7 @@ struct local_scheduler_state {
local_scheduler_state *
init_local_scheduler(event_loop *loop, const char *redis_addr, int redis_port) {
local_scheduler_state *state = malloc(sizeof(local_scheduler_state));
state->loop = loop;
state->db = db_connect(redis_addr, redis_port, "photon", "", -1);
db_attach(state->db, loop);
utarray_new(state->task_queue, &task_ptr_icd);
@@ -42,6 +47,14 @@ init_local_scheduler(event_loop *loop, const char *redis_addr, int redis_port) {
return state;
};
void free_local_scheduler(local_scheduler_state *s) {
db_disconnect(s->db);
utarray_free(s->task_queue);
utarray_free(s->available_worker_queue);
event_loop_destroy(s->loop);
free(s);
}
void handle_submit_task(local_scheduler_state *s, task_spec *task) {
/* Create a unique task instance ID. This is different from the task ID and
* is used to distinguish between potentially multiple executions of the
@@ -146,19 +159,33 @@ void new_client_connection(event_loop *loop, int listener_sock, void *context,
LOG_INFO("new connection with fd %d", new_socket);
}
/* We need this code so we can clean up when we get a SIGTERM signal. */
local_scheduler_state *g_state;
void signal_handler(int signal) {
if (signal == SIGTERM) {
free_local_scheduler(g_state);
exit(0);
}
}
/* End of the cleanup code. */
void start_server(const char *socket_name, const char *redis_addr,
int redis_port) {
int fd = bind_ipc_sock(socket_name);
event_loop *loop = event_loop_create();
local_scheduler_state *state =
init_local_scheduler(loop, redis_addr, redis_port);
g_state = init_local_scheduler(loop, redis_addr, redis_port);
/* Run event loop. */
event_loop_add_file(loop, fd, EVENT_LOOP_READ, new_client_connection, state);
event_loop_add_file(loop, fd, EVENT_LOOP_READ, new_client_connection,
g_state);
event_loop_run(loop);
}
int main(int argc, char *argv[]) {
signal(SIGTERM, signal_handler);
/* Path of the listening socket of the local scheduler. */
char *scheduler_socket_name = NULL;
/* IP address and port of redis. */
+25 -3
View File
@@ -1,6 +1,7 @@
from __future__ import print_function
import os
import signal
import subprocess
import sys
import unittest
@@ -9,6 +10,8 @@ import time
import photon
USE_VALGRIND = False
class TestPhotonClient(unittest.TestCase):
def setUp(self):
@@ -18,8 +21,15 @@ class TestPhotonClient(unittest.TestCase):
time.sleep(0.1)
scheduler_executable = os.path.join(os.path.abspath(os.path.dirname(__file__)), "../build/photon_scheduler")
scheduler_name = "/tmp/scheduler{}".format(random.randint(0, 10000))
self.p2 = subprocess.Popen([scheduler_executable, "-s", scheduler_name, "-r", "127.0.0.1:6379"])
time.sleep(0.1)
command = [scheduler_executable, "-s", scheduler_name, "-r", "127.0.0.1:6379"]
if USE_VALGRIND:
self.p2 = subprocess.Popen(["valgrind", "--track-origins=yes", "--leak-check=full", "--show-leak-kinds=all"] + command)
else:
self.p2 = subprocess.Popen(command)
if USE_VALGRIND:
time.sleep(1.0)
else:
time.sleep(0.1)
# Connect to the scheduler.
self.photon_client = photon.PhotonClient(scheduler_name)
@@ -27,7 +37,13 @@ class TestPhotonClient(unittest.TestCase):
# Kill the Redis server.
self.p1.kill()
# Kill the local scheduler.
self.p2.kill()
if USE_VALGRIND:
self.p2.send_signal(signal.SIGTERM)
self.p2.wait()
os._exit(self.p2.returncode)
else:
self.p2.kill()
def test_create(self):
l = [20 * "a", 20 * "b", 20 * "c"]
@@ -38,4 +54,10 @@ class TestPhotonClient(unittest.TestCase):
task = self.photon_client.get_task()
if __name__ == "__main__":
if len(sys.argv) > 1:
# pop the argument so we don't mess with unittest's own argument parser
arg = sys.argv.pop()
if arg == "valgrind":
USE_VALGRIND = True
print("Using valgrind for tests")
unittest.main(verbosity=2)