test-process-title-threadsafe.c
Go to the documentation of this file.
1 /* Copyright libuv project contributors. All rights reserved.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 * IN THE SOFTWARE.
20 */
21 
22 
23 #include "uv.h"
24 #include "task.h"
25 
26 #include <string.h>
27 
28 #ifdef __APPLE__
29 # define NUM_ITERATIONS 5
30 #else
31 # define NUM_ITERATIONS 50
32 #endif
33 
34 static const char* titles[] = {
35  "8L2NY0Kdj0XyNFZnmUZigIOfcWjyNr0SkMmUhKw99VLUsZFrvCQQC3XIRfNR8pjyMjXObllled",
36  "jUAcscJN49oLSN8GdmXj2Wo34XX2T2vp2j5khfajNQarlOulp57cE130yiY53ipJFnPyTn5i82",
37  "9niCI5icXGFS72XudhXqo5alftmZ1tpE7B3cwUmrq0CCDjC84FzBNB8XAHqvpNQfI2QAQG6ztT",
38  "n8qXVXuG6IEHDpabJgTEiwtpY6LHMZ8MgznnMpdHARu5EywufA6hcBaQfetb0YhEsK0ykDd7JU"
39 };
40 
41 static void getter_thread_body(void* arg) {
42  char buffer[512];
43  size_t len;
44 
45  for (;;) {
46  ASSERT(0 == uv_get_process_title(buffer, sizeof(buffer)));
47 
48  /* The maximum size of the process title on some platforms depends on
49  * the total size of the argv vector. It's therefore possible to read
50  * back a title that's shorter than what we submitted.
51  */
52  len = strlen(buffer);
53  ASSERT_GT(len, 0);
54 
55  ASSERT(
56  0 == strncmp(buffer, titles[0], len) ||
57  0 == strncmp(buffer, titles[1], len) ||
58  0 == strncmp(buffer, titles[2], len) ||
59  0 == strncmp(buffer, titles[3], len));
60 
61  uv_sleep(0);
62  }
63 }
64 
65 
66 static void setter_thread_body(void* arg) {
67  int i;
68 
69  for (i = 0; i < NUM_ITERATIONS; i++) {
74  }
75 }
76 
77 
78 TEST_IMPL(process_title_threadsafe) {
79  uv_thread_t setter_threads[4];
80  uv_thread_t getter_thread;
81  int i;
82 
83 #if defined(__sun) || defined(__CYGWIN__) || defined(__MSYS__) || \
84  defined(__MVS__) || defined(__PASE__)
85  RETURN_SKIP("uv_(get|set)_process_title is not implemented.");
86 #endif
87 
89  ASSERT(0 == uv_thread_create(&getter_thread, getter_thread_body, NULL));
90 
91  for (i = 0; i < (int) ARRAY_SIZE(setter_threads); i++)
92  ASSERT(0 == uv_thread_create(&setter_threads[i], setter_thread_body, NULL));
93 
94  for (i = 0; i < (int) ARRAY_SIZE(setter_threads); i++)
95  ASSERT(0 == uv_thread_join(&setter_threads[i]));
96 
97  return 0;
98 }
ARRAY_SIZE
#define ARRAY_SIZE(array)
Definition: bloaty.cc:101
task.h
getter_thread_body
static void getter_thread_body(void *arg)
Definition: test-process-title-threadsafe.c:41
string.h
ASSERT
#define ASSERT(expr)
Definition: task.h:102
titles
static const char * titles[]
Definition: test-process-title-threadsafe.c:34
uv_thread_join
UV_EXTERN int uv_thread_join(uv_thread_t *tid)
Definition: libuv/src/unix/thread.c:271
TEST_IMPL
TEST_IMPL(process_title_threadsafe)
Definition: test-process-title-threadsafe.c:78
xds_interop_client.int
int
Definition: xds_interop_client.py:113
arg
Definition: cmdline.cc:40
setter_thread_body
static void setter_thread_body(void *arg)
Definition: test-process-title-threadsafe.c:66
uv_set_process_title
UV_EXTERN int uv_set_process_title(const char *title)
Definition: aix.c:875
uv_thread_create
UV_EXTERN int uv_thread_create(uv_thread_t *tid, uv_thread_cb entry, void *arg)
Definition: libuv/src/unix/thread.c:209
buffer
char buffer[1024]
Definition: libuv/docs/code/idle-compute/main.c:8
uv_sleep
UV_EXTERN void uv_sleep(unsigned int msec)
Definition: unix/core.c:1521
uv.h
RETURN_SKIP
#define RETURN_SKIP(explanation)
Definition: task.h:262
uv_thread_t
pthread_t uv_thread_t
Definition: unix.h:134
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
ASSERT_GT
#define ASSERT_GT(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2076
uv_get_process_title
UV_EXTERN int uv_get_process_title(char *buffer, size_t size)
Definition: aix.c:906
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
NUM_ITERATIONS
#define NUM_ITERATIONS
Definition: test-process-title-threadsafe.c:31


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:26