1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

torture: Add local-g-lock-ping-pong

This is similar to the ctdb ping_pong test.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
Volker Lendecke 2017-05-22 21:55:11 +02:00 committed by Ralph Boehme
parent bfa0732359
commit cfb6568408
3 changed files with 98 additions and 4 deletions

View File

@ -130,5 +130,6 @@ bool run_g_lock2(int dummy);
bool run_g_lock3(int dummy);
bool run_g_lock4(int dummy);
bool run_g_lock5(int dummy);
bool run_g_lock_ping_pong(int dummy);
#endif /* __TORTURE_H__ */

View File

@ -30,12 +30,12 @@ static bool get_g_lock_ctx(TALLOC_CTX *mem_ctx,
struct messaging_context **msg,
struct g_lock_ctx **ctx)
{
*ev = samba_tevent_context_init(mem_ctx);
*ev = server_event_context();
if (*ev == NULL) {
fprintf(stderr, "tevent_context_init failed\n");
return false;
}
*msg = messaging_init(*ev, *ev);
*msg = server_messaging_context();
if (*msg == NULL) {
fprintf(stderr, "messaging_init failed\n");
TALLOC_FREE(*ev);
@ -558,8 +558,8 @@ bool run_g_lock5(int dummy)
if (child == 0) {
TALLOC_FREE(ctx);
TALLOC_FREE(msg);
TALLOC_FREE(ev);
status = reinit_after_fork(msg, ev, false, "");
close(ready_pipe[0]);
close(exit_pipe[1]);
@ -642,3 +642,95 @@ bool run_g_lock5(int dummy)
return true;
}
extern int torture_numops;
extern int torture_nprocs;
static struct timeval tp1, tp2;
static void start_timer(void)
{
gettimeofday(&tp1,NULL);
}
static double end_timer(void)
{
gettimeofday(&tp2,NULL);
return (tp2.tv_sec + (tp2.tv_usec*1.0e-6)) -
(tp1.tv_sec + (tp1.tv_usec*1.0e-6));
}
/*
* g_lock ping_pong
*/
bool run_g_lock_ping_pong(int dummy)
{
struct tevent_context *ev = NULL;
struct messaging_context *msg = NULL;
struct g_lock_ctx *ctx = NULL;
fstring name;
NTSTATUS status;
int i = 0;
bool ret = false;
bool ok;
unsigned count = 0;
torture_nprocs = MAX(2, torture_nprocs);
ok = get_g_lock_ctx(talloc_tos(), &ev, &msg, &ctx);
if (!ok) {
goto fail;
}
start_timer();
snprintf(name, sizeof(name), "ping_pong_%d", i);
status = g_lock_lock(ctx, name, G_LOCK_WRITE,
(struct timeval) { .tv_sec = 60 });
if (!NT_STATUS_IS_OK(status)) {
fprintf(stderr, "g_lock_lock failed: %s\n",
nt_errstr(status));
goto fail;
}
for (i=0; i<torture_numops; i++) {
name[10] = '0' + ((i+1) % torture_nprocs);
status = g_lock_lock(ctx, name, G_LOCK_WRITE,
(struct timeval) { .tv_sec = 60 });
if (!NT_STATUS_IS_OK(status)) {
fprintf(stderr, "g_lock_lock failed: %s\n",
nt_errstr(status));
goto fail;
}
name[10] = '0' + ((i) % torture_nprocs);
status = g_lock_unlock(ctx, name);
if (!NT_STATUS_IS_OK(status)) {
fprintf(stderr, "g_lock_unlock failed: %s\n",
nt_errstr(status));
goto fail;
}
count++;
if (end_timer() > 1.0) {
printf("%8u locks/sec\r",
(unsigned)(2*count/end_timer()));
fflush(stdout);
start_timer();
count=0;
}
}
ret = true;
fail:
TALLOC_FREE(ctx);
TALLOC_FREE(msg);
TALLOC_FREE(ev);
return ret;
}

View File

@ -11693,6 +11693,7 @@ static struct {
{ "LOCAL-G-LOCK3", run_g_lock3, 0 },
{ "LOCAL-G-LOCK4", run_g_lock4, 0 },
{ "LOCAL-G-LOCK5", run_g_lock5, 0 },
{ "LOCAL-G-LOCK-PING-PONG", run_g_lock_ping_pong, 0 },
{ "LOCAL-CANONICALIZE-PATH", run_local_canonicalize_path, 0 },
{ "qpathinfo-bufsize", run_qpathinfo_bufsize, 0 },
{NULL, NULL, 0}};