Adding upstream version 2.0.24.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e508fcfeb9
commit
afb0a8fea7
118 changed files with 45084 additions and 0 deletions
tests
77
tests/test_client_thread.c
Normal file
77
tests/test_client_thread.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* \file test_client_thread.c
|
||||
* \author Radek Krejci <rkrejci@cesnet.cz>
|
||||
* \brief libnetconf2 tests - threads functions in client
|
||||
*
|
||||
* Copyright (c) 2017 CESNET, z.s.p.o.
|
||||
*
|
||||
* This source code is licensed under BSD 3-Clause License (the "License").
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <libyang/libyang.h>
|
||||
|
||||
#include <session_client.h>
|
||||
#include "tests/config.h"
|
||||
|
||||
#define nc_assert(cond) if (!(cond)) { fprintf(stderr, "assert failed (%s:%d)\n", __FILE__, __LINE__); exit(1); }
|
||||
|
||||
static void *
|
||||
thread(void *arg)
|
||||
{
|
||||
/* default search path is NULL */
|
||||
nc_assert(nc_client_get_schema_searchpath() == NULL);
|
||||
|
||||
/* use the context shared from the main thread */
|
||||
nc_client_set_thread_context(arg);
|
||||
|
||||
/* check that we have now the search path set in main thread */
|
||||
nc_assert(strcmp(nc_client_get_schema_searchpath(), "/tmp") == 0);
|
||||
/* and change it to check it later in main thread */
|
||||
nc_assert(nc_client_set_schema_searchpath("/etc") == 0)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
void *arg;
|
||||
pthread_t t;
|
||||
int r;
|
||||
|
||||
nc_client_init();
|
||||
|
||||
/*
|
||||
* TEST sharing the thread context
|
||||
*/
|
||||
nc_assert(nc_client_set_schema_searchpath("/tmp") == 0)
|
||||
|
||||
/* get the context for sharing */
|
||||
arg = nc_client_get_thread_context();
|
||||
|
||||
/* create new thread and provide the context */
|
||||
r = pthread_create(&t, NULL, &thread, arg);
|
||||
nc_assert(r == 0);
|
||||
|
||||
pthread_join(t, NULL);
|
||||
|
||||
/* check the changed search path value from the thread */
|
||||
nc_assert(strcmp(nc_client_get_schema_searchpath(), "/etc") == 0);
|
||||
|
||||
/* cleanup */
|
||||
nc_client_destroy();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue