Skip to content
Snippets Groups Projects
Commit b3e3317a authored by ctiller's avatar ctiller Committed by Craig Tiller
Browse files

Seed random numbers in each process based on pid.

This causes get_unused_port_or_die to try different port numbers in each
concurrently running tests, and consequently enables some parallelism of test
processes.
	Change on 2015/01/05 by ctiller <ctiller@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=83289374
parent 156e67d4
No related branches found
No related tags found
No related merge requests found
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
...@@ -80,6 +81,9 @@ int main(int argc, char **argv) { ...@@ -80,6 +81,9 @@ int main(int argc, char **argv) {
pid_t svr; pid_t svr;
int ret; int ret;
int do_ipv6 = 1; int do_ipv6 = 1;
/* seed rng with pid, so we don't end up with the same random numbers as a
concurrently running test binary */
srand(getpid());
if (!grpc_ipv6_loopback_available()) { if (!grpc_ipv6_loopback_available()) {
gpr_log(GPR_INFO, "Can't bind to ::1. Skipping IPv6 tests."); gpr_log(GPR_INFO, "Can't bind to ::1. Skipping IPv6 tests.");
do_ipv6 = 0; do_ipv6 = 0;
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
...@@ -53,6 +54,9 @@ int main(int argc, char **argv) { ...@@ -53,6 +54,9 @@ int main(int argc, char **argv) {
char *args[10]; char *args[10];
int status; int status;
pid_t svr, cli; pid_t svr, cli;
/* seed rng with pid, so we don't end up with the same random numbers as a
concurrently running test binary */
srand(getpid());
/* figure out where we are */ /* figure out where we are */
if (lslash) { if (lslash) {
memcpy(root, me, lslash - me); memcpy(root, me, lslash - me);
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
...@@ -53,6 +54,9 @@ int main(int argc, char **argv) { ...@@ -53,6 +54,9 @@ int main(int argc, char **argv) {
char *args[10]; char *args[10];
int status; int status;
pid_t svr, cli; pid_t svr, cli;
/* seed rng with pid, so we don't end up with the same random numbers as a
concurrently running test binary */
srand(getpid());
/* figure out where we are */ /* figure out where we are */
if (lslash) { if (lslash) {
memcpy(root, me, lslash - me); memcpy(root, me, lslash - me);
......
...@@ -33,4 +33,11 @@ ...@@ -33,4 +33,11 @@
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
void grpc_test_init(int argc, char **argv) {} #include <stdlib.h>
#include <unistd.h>
void grpc_test_init(int argc, char **argv) {
/* seed rng with pid, so we don't end up with the same random numbers as a
concurrently running test binary */
srand(getpid());
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment