Skip to content

Commit

Permalink
Merge pull request #189 from thallium/v0.43.0-release
Browse files Browse the repository at this point in the history
(v0.43) Return another error if only one data point has been recorded
  • Loading branch information
pshipton authored Dec 17, 2023
2 parents d810fcb + 012d84c commit 7c7beec
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
14 changes: 6 additions & 8 deletions fvtest/porttest/si.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1690,19 +1690,17 @@ TEST(PortSysinfoTest, sysinfo_test_get_CPU_load)
{
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());

/* As per the API specification the first two calls to this API will return a negative portable error code. However
* for the purposes of this test we will not be testing this. This is because the test infrastructure is setup such
* that we cannot guarantee that no other test has called omrsysinfo_get_CPU_utlization or omrsysinfo_get_CPU_load
* up to this point. If some other test did call these APIs then the internal buffers would have been populated and
* as such the omrsysinfo_get_CPU_load could return a zero return code on the very first invocation within this
* test.
/* As per the API specification if only one data point has been recorded this API will return a negative portable
* error code. However for the purposes of this test we will not be testing this. This is because the test infrastructure
* is setup such that we cannot guarantee that no other test has called omrsysinfo_get_CPU_load up to this point. If
* some other test calls this API then the internal buffers would have been populated and as such the omrsysinfo_get_CPU_load
* could return a zero return code on the very first invocation within this test.
*
* To avoid inter-test dependencies we do not assert on the return value of the first two calls here, and only test
* To avoid inter-test dependencies we do not assert on the return value of the first call here, and only test
* that the API returns valid numbers within the range outlined in the API specification.
*/
double cpuLoad;
omrsysinfo_get_CPU_load(&cpuLoad);
omrsysinfo_get_CPU_load(&cpuLoad);

/* Sleep for 100ms before re-sampling processor usage stats. This allows other processes and the operating system to
* use the CPU and drive up the user and kernel utilization. The call to cpuBurner probably won't be optimized out,
Expand Down
1 change: 1 addition & 0 deletions include_core/omrporterror.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#define OMRPORT_ERROR_INVALID_HANDLE (OMRPORT_ERROR_BASE-17)
#define OMRPORT_ERROR_NOT_SUPPORTED_ON_THIS_PLATFORM (OMRPORT_ERROR_BASE-18)
#define OMRPORT_ERROR_INVALID_ARGUMENTS (OMRPORT_ERROR_BASE-19)
#define OMRPORT_ERROR_INSUFFICIENT_DATA (OMRPORT_ERROR_BASE-20)
/** @} */

/**
Expand Down
8 changes: 4 additions & 4 deletions port/common/omrsysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,10 @@ omrsysinfo_get_CPU_utilization(struct OMRPortLibrary *portLibrary, struct J9Sysi
* @param[out] cpuLoad the cumulative CPU utilization of all CPUs on the system
*
* @return
* - 0 on success
* - \arg OMRPORT_ERROR_OPFAILED on the first two invocations of this API
* - \arg OMRPORT_ERROR_OPFAILED if less than 10ns have passed since the second call to this API
* - negative portable error code on other failures
* \arg 0 on success
* \arg OMRPORT_ERROR_INSUFFICIENT_DATA if only one data point has been recorded
* \arg OMRPORT_ERROR_OPFAILED if less than 10 ms have passed since the last call to this API
* \arg negative portable error code on other failures
*/
intptr_t
omrsysinfo_get_CPU_load(struct OMRPortLibrary *portLibrary, double *cpuLoad)
Expand Down
4 changes: 2 additions & 2 deletions port/unix/omrsysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -4642,7 +4642,7 @@ omrsysinfo_get_CPU_load(struct OMRPortLibrary *portLibrary, double *cpuLoad)
if (oldestCPUTime->timestamp == 0) {
*oldestCPUTime = currentCPUTime;
*latestCPUTime = currentCPUTime;
return OMRPORT_ERROR_OPFAILED;
return OMRPORT_ERROR_INSUFFICIENT_DATA;
}

/* Calculate using the most recent value in the history */
Expand Down Expand Up @@ -4674,7 +4674,7 @@ omrsysinfo_get_CPU_load(struct OMRPortLibrary *portLibrary, double *cpuLoad)
if (oldestCPUTime->timestamp == 0) {
*oldestCPUTime = currentCPUTime;
*latestCPUTime = currentCPUTime;
return OMRPORT_ERROR_OPFAILED;
return OMRPORT_ERROR_INSUFFICIENT_DATA;
}

/* Calculate using the most recent value in the history */
Expand Down
2 changes: 1 addition & 1 deletion port/win32/omrsysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ omrsysinfo_get_CPU_load(struct OMRPortLibrary *portLibrary, double *cpuLoad)
if (oldestCPUTime->timestamp == 0) {
*oldestCPUTime = currentCPUTime;
*latestCPUTime = currentCPUTime;
return OMRPORT_ERROR_OPFAILED;
return OMRPORT_ERROR_INSUFFICIENT_DATA;
}

/* Calculate using the most recent value in the history */
Expand Down

0 comments on commit 7c7beec

Please sign in to comment.