test-process-priority.c
Go to the documentation of this file.
1 /* Copyright libuv 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 #include "uv.h"
23 #include "task.h"
24 
25 
26 TEST_IMPL(process_priority) {
27  int priority;
28  int r;
29  int i;
30 
31 #if defined(__MVS__)
32  if (uv_os_setpriority(0, 0) == UV_ENOSYS)
33  RETURN_SKIP("functionality not supported on zOS");
34 #endif
35 
36  /* Verify that passing a NULL pointer returns UV_EINVAL. */
37  r = uv_os_getpriority(0, NULL);
38  ASSERT(r == UV_EINVAL);
39 
40  /* Verify that all valid values work. */
41  for (i = UV_PRIORITY_HIGHEST; i <= UV_PRIORITY_LOW; i++) {
42  r = uv_os_setpriority(0, i);
43 
44  /* If UV_EACCES is returned, the current user doesn't have permission to
45  set this specific priority. */
46  if (r == UV_EACCES)
47  continue;
48 
49  ASSERT(r == 0);
51 
52  /* Verify that the priority values match on Unix, and are range mapped
53  on Windows. */
54 #ifndef _WIN32
55  ASSERT(priority == i);
56 #else
57  /* On Windows, only elevated users can set UV_PRIORITY_HIGHEST. Other
58  users will silently be set to UV_PRIORITY_HIGH. */
59  if (i < UV_PRIORITY_HIGH)
61  else if (i < UV_PRIORITY_ABOVE_NORMAL)
63  else if (i < UV_PRIORITY_NORMAL)
65  else if (i < UV_PRIORITY_BELOW_NORMAL)
67  else if (i < UV_PRIORITY_LOW)
69  else
71 #endif
72 
73  /* Verify that the current PID and 0 are equivalent. */
75  ASSERT(priority == r);
76  }
77 
78  /* Verify that invalid priorities return UV_EINVAL. */
79  ASSERT(uv_os_setpriority(0, UV_PRIORITY_HIGHEST - 1) == UV_EINVAL);
80  ASSERT(uv_os_setpriority(0, UV_PRIORITY_LOW + 1) == UV_EINVAL);
81 
82  return 0;
83 }
UV_PRIORITY_HIGH
#define UV_PRIORITY_HIGH
Definition: uv.h:1203
UV_PRIORITY_LOW
#define UV_PRIORITY_LOW
Definition: uv.h:1199
UV_PRIORITY_ABOVE_NORMAL
#define UV_PRIORITY_ABOVE_NORMAL
Definition: uv.h:1202
task.h
priority
int priority
Definition: abseil-cpp/absl/synchronization/internal/graphcycles.cc:286
uv_os_getpid
UV_EXTERN uv_pid_t uv_os_getpid(void)
Definition: unix/core.c:1392
TEST_IMPL
TEST_IMPL(process_priority)
Definition: test-process-priority.c:26
ASSERT
#define ASSERT(expr)
Definition: task.h:102
uv_os_getpriority
UV_EXTERN int uv_os_getpriority(uv_pid_t pid, int *priority)
Definition: unix/core.c:1402
UV_PRIORITY_BELOW_NORMAL
#define UV_PRIORITY_BELOW_NORMAL
Definition: uv.h:1200
UV_PRIORITY_HIGHEST
#define UV_PRIORITY_HIGHEST
Definition: uv.h:1204
uv.h
uv_os_setpriority
UV_EXTERN int uv_os_setpriority(uv_pid_t pid, int priority)
Definition: unix/core.c:1419
UV_PRIORITY_NORMAL
#define UV_PRIORITY_NORMAL
Definition: uv.h:1201
fix_build_deps.r
r
Definition: fix_build_deps.py:491
RETURN_SKIP
#define RETURN_SKIP(explanation)
Definition: task.h:262
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:30