51 lines
2.4 KiB
C
51 lines
2.4 KiB
C
/* Fake NVIDIA entrypoints for exercising the real preload adapter's ABI.
|
|
* No GPU or proprietary library is used. Compile with vendor/NvFBC.h.
|
|
*/
|
|
#include "NvFBC.h"
|
|
extern void *dlsym(void *, const char *);
|
|
static int test_case, captured_cursor, output_id, sampling;
|
|
static NVFBCSTATUS NVFBCAPI mock_capture(const NVFBC_SESSION_HANDLE handle,
|
|
NVFBC_CREATE_CAPTURE_SESSION_PARAMS *p) {
|
|
(void)handle;
|
|
captured_cursor = p->bWithCursor;
|
|
output_id = p->dwOutputId;
|
|
sampling = p->dwSamplingRateMs;
|
|
return test_case == 6 ? NVFBC_ERR_INTERNAL : NVFBC_SUCCESS;
|
|
}
|
|
static NVFBCSTATUS NVFBCAPI mock_status(const NVFBC_SESSION_HANDLE handle,
|
|
NVFBC_GET_STATUS_PARAMS *p) {
|
|
(void)handle;
|
|
p->bIsCapturePossible = test_case == 4 ? NVFBC_FALSE : NVFBC_TRUE;
|
|
p->screenSize = (NVFBC_SIZE){test_case == 3 ? 1920 : 2560, 1440};
|
|
p->bXRandRAvailable = NVFBC_TRUE;
|
|
p->dwOutputNum = test_case == 5 ? 2 : 0;
|
|
return NVFBC_SUCCESS;
|
|
}
|
|
NVFBCSTATUS NVFBCAPI NvFBCCreateInstance(NVFBC_API_FUNCTION_LIST *f) {
|
|
f->nvFBCCreateCaptureSession = mock_capture;
|
|
f->nvFBCGetStatus = mock_status;
|
|
return NVFBC_SUCCESS;
|
|
}
|
|
int run_test(int which, int leased, int headless) {
|
|
test_case = which;
|
|
PNVFBCCREATEINSTANCE create = (PNVFBCCREATEINSTANCE)dlsym((void *)0, "NvFBCCreateInstance");
|
|
if (!create) return 1;
|
|
NVFBC_API_FUNCTION_LIST f = {.dwVersion=NVFBC_VERSION};
|
|
if (create(&f) != NVFBC_SUCCESS) return 2;
|
|
NVFBC_CREATE_CAPTURE_SESSION_PARAMS p = {
|
|
.dwVersion = which == 7 ? 0 : NVFBC_CREATE_CAPTURE_SESSION_PARAMS_VER,
|
|
.bWithCursor = NVFBC_TRUE, .dwOutputId = 73, .dwSamplingRateMs=16
|
|
};
|
|
NVFBCSTATUS status = f.nvFBCCreateCaptureSession(1, &p);
|
|
if (status != (which == 6 ? NVFBC_ERR_INTERNAL : NVFBC_SUCCESS)) return 3;
|
|
if (captured_cursor != (leased ? NVFBC_FALSE : NVFBC_TRUE)) return 4;
|
|
if (p.bWithCursor != NVFBC_TRUE || p.dwOutputId != 73 || output_id != 73 || sampling != 16) return 5;
|
|
NVFBC_GET_STATUS_PARAMS s = {.dwVersion=which == 8 ? 0 : NVFBC_GET_STATUS_PARAMS_VER};
|
|
if (f.nvFBCGetStatus(1, &s) != NVFBC_SUCCESS) return 6;
|
|
int enumerate_root = headless && which != 3 && which != 4 && which != 5;
|
|
if (enumerate_root) {
|
|
if (s.dwOutputNum != 1 || s.bXRandRAvailable || s.outputs[0].trackedBox.w != 2560 || s.outputs[0].trackedBox.h != 1440) return 7;
|
|
} else if (s.dwOutputNum != (which == 5 ? 2U : 0U) || !s.bXRandRAvailable) return 8;
|
|
return 0;
|
|
}
|