diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:17:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:17:27 +0000 |
commit | f215e02bf85f68d3a6106c2a1f4f7f063f819064 (patch) | |
tree | 6bb5b92c046312c4e95ac2620b10ddf482d3fa8b /src/VBox/HostServices/testcase | |
parent | Initial commit. (diff) | |
download | virtualbox-f215e02bf85f68d3a6106c2a1f4f7f063f819064.tar.xz virtualbox-f215e02bf85f68d3a6106c2a1f4f7f063f819064.zip |
Adding upstream version 7.0.14-dfsg.upstream/7.0.14-dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/VBox/HostServices/testcase')
-rw-r--r-- | src/VBox/HostServices/testcase/Makefile.kmk | 52 | ||||
-rw-r--r-- | src/VBox/HostServices/testcase/tstHGCMSvc.cpp | 119 |
2 files changed, 171 insertions, 0 deletions
diff --git a/src/VBox/HostServices/testcase/Makefile.kmk b/src/VBox/HostServices/testcase/Makefile.kmk new file mode 100644 index 00000000..a6b63610 --- /dev/null +++ b/src/VBox/HostServices/testcase/Makefile.kmk @@ -0,0 +1,52 @@ +# $Id: Makefile.kmk $ +## @file +# Sub-Makefile for the HGCM service testcase. +# + +# +# Copyright (C) 2009-2023 Oracle and/or its affiliates. +# +# This file is part of VirtualBox base platform packages, as +# available from https://www.virtualbox.org. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation, in version 3 of the +# License. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see <https://www.gnu.org/licenses>. +# +# SPDX-License-Identifier: GPL-3.0-only +# + +SUB_DEPTH = ../../../.. +include $(KBUILD_PATH)/subheader.kmk + +if defined(VBOX_WITH_TESTCASES) && !defined(VBOX_ONLY_ADDITIONS) && !defined(VBOX_ONLY_SDK) + + # + # Set this in LocalConfig.kmk if you are working on HGCM service internals + # to automatically run the unit test at build time: + # OTHERS += $(tstHGCMSvc_0_OUTDIR)/tstHGCMSvc.run + # + PROGRAMS += tstHGCMSvc + TESTING += $(tstHGCMSvc_0_OUTDIR)/tstHGCMSvc.run + tstHGCMSvc_TEMPLATE = VBoxR3TstExe + tstHGCMSvc_DEFS = VBOX_WITH_HGCM VBOX_TEST_HGCM_PARMS + tstHGCMSvc_SOURCES = tstHGCMSvc.cpp + tstHGCMSvc_CLEAN = $(tstHGCMSvc_0_OUTDIR)/tstHGCMSvc.run + + $$(tstHGCMSvc_0_OUTDIR)/tstHGCMSvc.run: $$(tstHGCMSvc_1_STAGE_TARGET) + export VBOX_LOG_DEST=nofile; $(tstHGCMSvc_1_STAGE_TARGET) quiet + $(QUIET)$(APPEND) -t "$@" "done" + +endif # VBOX_WITH_TESTCASES + +include $(FILE_KBUILD_SUB_FOOTER) + diff --git a/src/VBox/HostServices/testcase/tstHGCMSvc.cpp b/src/VBox/HostServices/testcase/tstHGCMSvc.cpp new file mode 100644 index 00000000..9c2ee782 --- /dev/null +++ b/src/VBox/HostServices/testcase/tstHGCMSvc.cpp @@ -0,0 +1,119 @@ +/* $Id: tstHGCMSvc.cpp $ */ +/** @file + * HGCM Service Testcase. + */ + +/* + * Copyright (C) 2009-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#include <VBox/hgcmsvc.h> +#include <iprt/initterm.h> +#include <iprt/test.h> + +/** Test the getString member function. Indirectly tests the getPointer + * and getBuffer APIs. + * @param hTest an running IPRT test + * @param type the type that the parameter should be set to before + * calling getString + * @param pcch the value that the parameter should be set to before + * calling getString, and also the address (!) which we + * expect getString to return. Stricter than needed of + * course, but I was feeling lazy. + * @param cb the size that the parameter should be set to before + * calling getString, and also the size which we expect + * getString to return. + * @param rcExp the expected return value of the call to getString. + */ +void doTestGetString(VBOXHGCMSVCPARM *pParm, RTTEST hTest, uint32_t type, + const char *pcch, uint32_t cb, int rcExp) +{ + /* An RTTest API like this, which would print out an additional line + * of context if a test failed, would be nice. This is because the + * line number alone doesn't help much here, given that this is a + * subroutine called many times. */ + /* + RTTestContextF(hTest, + ("doTestGetString, type=%u, pcch=%p, acp=%u, rcExp=%Rrc", + type, pcch, acp, rcExp)); + */ + HGCMSvcSetPv(pParm, (void *)pcch, cb); + pParm->type = type; /* in case we don't want VBOX_HGCM_SVC_PARM_PTR */ + const char *pcch2 = NULL; + uint32_t cb2 = 0; + int rc = HGCMSvcGetCStr(pParm, &pcch2, &cb2); + RTTEST_CHECK_RC(hTest, rc, rcExp); + if (RT_SUCCESS(rcExp)) + { + RTTEST_CHECK_MSG_RETV(hTest, (pcch2 == pcch), + (hTest, "expected %p, got %p", pcch, pcch2)); + RTTEST_CHECK_MSG_RETV(hTest, (cb2 == cb), + (hTest, "expected %u, got %u", cb, cb2)); + } +} + +/** Run some unit tests on the getString method and indirectly test + * getPointer and getBuffer as well. */ +void testGetString(VBOXHGCMSVCPARM *pParm, RTTEST hTest) +{ + RTTestSub(hTest, "HGCM string parameter handling"); + doTestGetString(pParm, hTest, VBOX_HGCM_SVC_PARM_32BIT, "test", 3, + VERR_INVALID_PARAMETER); + doTestGetString(pParm, hTest, VBOX_HGCM_SVC_PARM_PTR, "test", 5, + VINF_SUCCESS); + doTestGetString(pParm, hTest, VBOX_HGCM_SVC_PARM_PTR, "test", 3, + VERR_BUFFER_OVERFLOW); + doTestGetString(pParm, hTest, VBOX_HGCM_SVC_PARM_PTR, "test\xf0", 6, + VERR_INVALID_UTF8_ENCODING); + doTestGetString(pParm, hTest, VBOX_HGCM_SVC_PARM_PTR, "test", 0, + VERR_INVALID_PARAMETER); + doTestGetString(pParm, hTest, VBOX_HGCM_SVC_PARM_PTR, (const char *)0x1, 5, + VERR_INVALID_PARAMETER); + RTTestSubDone(hTest); +} + +int main() +{ + /* + * Init the runtime, test and say hello. + */ + RTTEST hTest; + int rc = RTTestInitAndCreate("tstHGCMSvc", &hTest); + if (rc) + return rc; + RTTestBanner(hTest); + + /* + * Run the test. + */ + VBOXHGCMSVCPARM parm; + testGetString(&parm, hTest); + + /* + * Summary + */ + return RTTestSummaryAndDestroy(hTest); +} + |