libuv-svace-build
83 строки · 2.9 Кб
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
26TEST_IMPL(process_priority) {27int priority;28int r;29int i;30
31#if defined(__MVS__)32if (uv_os_setpriority(0, 0) == UV_ENOSYS)33RETURN_SKIP("functionality not supported on zOS");34#endif35
36/* Verify that passing a NULL pointer returns UV_EINVAL. */37r = uv_os_getpriority(0, NULL);38ASSERT_EQ(r, UV_EINVAL);39
40/* Verify that all valid values work. */41for (i = UV_PRIORITY_HIGHEST; i <= UV_PRIORITY_LOW; i++) {42r = uv_os_setpriority(0, i);43
44/* If UV_EACCES is returned, the current user doesn't have permission to45set this specific priority. */
46if (r == UV_EACCES)47continue;48
49ASSERT_OK(r);50ASSERT_OK(uv_os_getpriority(0, &priority));51
52/* Verify that the priority values match on Unix, and are range mapped53on Windows. */
54#ifndef _WIN3255ASSERT_EQ(priority, i);56#else57/* On Windows, only elevated users can set UV_PRIORITY_HIGHEST. Other58users will silently be set to UV_PRIORITY_HIGH. */
59if (i < UV_PRIORITY_HIGH)60ASSERT(priority == UV_PRIORITY_HIGHEST || priority == UV_PRIORITY_HIGH);61else if (i < UV_PRIORITY_ABOVE_NORMAL)62ASSERT_EQ(priority, UV_PRIORITY_HIGH);63else if (i < UV_PRIORITY_NORMAL)64ASSERT_EQ(priority, UV_PRIORITY_ABOVE_NORMAL);65else if (i < UV_PRIORITY_BELOW_NORMAL)66ASSERT_EQ(priority, UV_PRIORITY_NORMAL);67else if (i < UV_PRIORITY_LOW)68ASSERT_EQ(priority, UV_PRIORITY_BELOW_NORMAL);69else70ASSERT_EQ(priority, UV_PRIORITY_LOW);71#endif72
73/* Verify that the current PID and 0 are equivalent. */74ASSERT_OK(uv_os_getpriority(uv_os_getpid(), &r));75ASSERT_EQ(priority, r);76}77
78/* Verify that invalid priorities return UV_EINVAL. */79ASSERT_EQ(uv_os_setpriority(0, UV_PRIORITY_HIGHEST - 1), UV_EINVAL);80ASSERT_EQ(uv_os_setpriority(0, UV_PRIORITY_LOW + 1), UV_EINVAL);81
82return 0;83}
84