add CPU tests

pull/3901/head
Alistair Veitch 9 years ago
parent 63544f7808
commit dcfb3fe482
  1. 34
      Makefile
  2. 8
      build.yaml
  3. 135
      test/core/support/cpu_test.c
  4. 12
      tools/run_tests/sources_and_headers.json
  5. 18
      tools/run_tests/tests.json
  6. 25
      vsprojects/buildtests_c.sln

File diff suppressed because one or more lines are too long

@ -969,6 +969,14 @@ targets:
deps:
- gpr_test_util
- gpr
- name: gpr_cpu_test
build: test
language: c
src:
- test/core/support/cpu_test.c
deps:
- gpr_test_util
- gpr
- name: gpr_env_test
build: test
language: c

@ -0,0 +1,135 @@
/*
*
* Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Test gpr per-cpu support:
gpr_cpu_num_cores()
gpr_cpu_current_cpu()
*/
#include <grpc/support/alloc.h>
#include <grpc/support/cpu.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
#include <grpc/support/time.h>
#include <stdio.h>
#include <string.h>
#include "test/core/util/test_config.h"
/* Test structure is essentially:
1) Figure out how many cores are present on the test system
2) Create 3 times that many threads
3) Have each thread do some amount of work (basically want to
gaurantee that all threads are running at once, and enough of them
to run on all cores).
4) Each thread checks what core it is running on, and marks that core
as "used" in the test.
5) Check that all cores were "used"
The test will fail if:
1) gpr_cpu_num_cores() == 0
2) The result of gpr_cpu_current_cpu() >= gpr_cpu_num_cores()
3) Not all cores are used/seen in the test. If a system does not exhibit
this property (e.g. some cores reserved/unusable), then this condition
will have to be rethought.
*/
/* Status shared across threads */
struct cpu_test {
gpr_mu mu;
int nthreads;
gpr_uint32 ncores;
int is_done;
gpr_cv done_cv;
int *used; /* is this core used? */
int r; /* random number */
};
static void worker_thread(void *arg) {
struct cpu_test *ct = (struct cpu_test *)arg;
gpr_uint32 cpu;
int r = 12345678;
int i, j;
for (i = 0; i < 1000; i++) {
/* run for a bit - just calculate something random. */
for (j = 0; j < 1000000; j++) {
r = (r * 17) & ((r - i) | (r * i));
}
cpu = gpr_cpu_current_cpu();
GPR_ASSERT(cpu < ct->ncores);
gpr_mu_lock(&ct->mu);
ct->used[cpu] = 1;
gpr_mu_unlock(&ct->mu);
}
gpr_mu_lock(&ct->mu);
fprintf(stderr, "thread done on core %d\n", cpu);
ct->r = r; /* make it look like we care about r's value... */
ct->nthreads--;
if (ct->nthreads == 0) {
ct->is_done = 1;
gpr_cv_signal(&ct->done_cv);
}
gpr_mu_unlock(&ct->mu);
}
static void cpu_test(void) {
gpr_uint32 i;
struct cpu_test ct;
gpr_thd_id thd;
ct.ncores = gpr_cpu_num_cores();
GPR_ASSERT(ct.ncores > 0);
fprintf(stderr, "#cores = %d\n", ct.ncores);
ct.nthreads = (int)ct.ncores * 3;
ct.used = gpr_malloc(ct.ncores * sizeof(int));
memset(ct.used, 0, ct.ncores * sizeof(int));
gpr_mu_init(&ct.mu);
gpr_cv_init(&ct.done_cv);
ct.is_done = 0;
for (i = 0; i < ct.ncores * 3; i++) {
GPR_ASSERT(gpr_thd_new(&thd, &worker_thread, &ct, NULL));
}
gpr_mu_lock(&ct.mu);
while (!ct.is_done) {
gpr_cv_wait(&ct.done_cv, &ct.mu, gpr_inf_future(GPR_CLOCK_REALTIME));
}
gpr_mu_unlock(&ct.mu);
for (i = 0; i < ct.ncores; i++) {
GPR_ASSERT(ct.used[i]);
}
}
int main(int argc, char *argv[]) {
grpc_test_init(argc, argv);
cpu_test();
return 0;
}

@ -230,6 +230,18 @@
"test/core/support/cmdline_test.c"
]
},
{
"deps": [
"gpr",
"gpr_test_util"
],
"headers": [],
"language": "c",
"name": "gpr_cpu_test",
"src": [
"test/core/support/cpu_test.c"
]
},
{
"deps": [
"gpr",

@ -225,6 +225,24 @@
"windows"
]
},
{
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"exclude_configs": [],
"flaky": false,
"language": "c",
"name": "gpr_cpu_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
]
},
{
"ci_platforms": [
"linux",

@ -697,6 +697,15 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gpr_cmdline_test", "vcxproj
{B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gpr_cpu_test", "vcxproj\test\gpr_cpu_test\gpr_cpu_test.vcxproj", "{0CB6DF66-4346-CCD0-C94B-318321C46501}"
ProjectSection(myProperties) = preProject
lib = "False"
EndProjectSection
ProjectSection(ProjectDependencies) = postProject
{EAB0A629-17A9-44DB-B5FF-E91A721FE037} = {EAB0A629-17A9-44DB-B5FF-E91A721FE037}
{B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gpr_env_test", "vcxproj\test\gpr_env_test\gpr_env_test.vcxproj", "{07149650-E8AF-B3D8-9D5B-BC34DC909DB8}"
ProjectSection(myProperties) = preProject
lib = "False"
@ -8957,6 +8966,22 @@ Global
{10668A5D-65CD-F530-22D0-747B395B4C26}.Release-DLL|Win32.Build.0 = Release|Win32
{10668A5D-65CD-F530-22D0-747B395B4C26}.Release-DLL|x64.ActiveCfg = Release|x64
{10668A5D-65CD-F530-22D0-747B395B4C26}.Release-DLL|x64.Build.0 = Release|x64
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Debug|Win32.ActiveCfg = Debug|Win32
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Debug|x64.ActiveCfg = Debug|x64
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Release|Win32.ActiveCfg = Release|Win32
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Release|x64.ActiveCfg = Release|x64
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Debug|Win32.Build.0 = Debug|Win32
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Debug|x64.Build.0 = Debug|x64
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Release|Win32.Build.0 = Release|Win32
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Release|x64.Build.0 = Release|x64
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Debug-DLL|Win32.ActiveCfg = Debug|Win32
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Debug-DLL|Win32.Build.0 = Debug|Win32
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Debug-DLL|x64.ActiveCfg = Debug|x64
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Debug-DLL|x64.Build.0 = Debug|x64
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Release-DLL|Win32.ActiveCfg = Release|Win32
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Release-DLL|Win32.Build.0 = Release|Win32
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Release-DLL|x64.ActiveCfg = Release|x64
{0CB6DF66-4346-CCD0-C94B-318321C46501}.Release-DLL|x64.Build.0 = Release|x64
{07149650-E8AF-B3D8-9D5B-BC34DC909DB8}.Debug|Win32.ActiveCfg = Debug|Win32
{07149650-E8AF-B3D8-9D5B-BC34DC909DB8}.Debug|x64.ActiveCfg = Debug|x64
{07149650-E8AF-B3D8-9D5B-BC34DC909DB8}.Release|Win32.ActiveCfg = Release|Win32

Loading…
Cancel
Save