~ubuntu-branches/ubuntu/karmic/virtualbox-ose/karmic-updates

« back to all changes in this revision

Viewing changes to src/VBox/Runtime/testcase/tstInlineAsm.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-09-14 18:25:07 UTC
  • mfrom: (0.4.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090914182507-c98g07mq16hjmn6d
Tags: 3.0.6-dfsg-1ubuntu1
* Merge from debian unstable (LP: #429697), remaining changes:
  - Enable DKMS support on virtualbox host and guest modules (LP: #267097)
    - Drop virtualbox-ose{-guest,}-modules-* package templates
    - Recommend *-source instead of *-modules packages
    - Replace error messages related to missing/mismatched
      kernel module accordingly
  - Autoload kernel module
    - LOAD_VBOXDRV_MODULE=1 in virtualbox-ose.default
  - Disable update action
    - patches/u01-disable-update-action.dpatch
  - Virtualbox should go in Accessories, not in System tools (LP: #288590)
    - virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add apport hook
    - virtualbox-ose.files/source_virtualbox-ose.py
    - virtualbox-ose.install
  - Add launchpad integration
    - control
    - lpi-bug.xpm
    - patches/u02-lp-integration.dpatch
  - virtualbox, virtualbox-* (names of the upstream proprietary packages)
    conflict with virtualbox-ose (LP: #379878)
* Make debug package depend on normal or guest utils package
* Drop patches/22-pulseaudio-stubs.dpatch (applied upstream)
* Rename Ubuntu specific patches to uXX-*.dpatch
* Fix lintian warnings in maintainer scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include <iprt/initterm.h>
38
38
#include <iprt/param.h>
39
39
#include <iprt/thread.h>
40
 
 
41
 
 
42
 
/*******************************************************************************
43
 
*   Global Variables                                                           *
44
 
*******************************************************************************/
45
 
/** Global error count. */
46
 
static unsigned g_cErrors;
 
40
#include <iprt/test.h>
 
41
 
47
42
 
48
43
 
49
44
/*******************************************************************************
54
49
    { \
55
50
        if ((val) != (expect)) \
56
51
        { \
57
 
            g_cErrors++; \
 
52
            RTTestIErrorInc(); \
58
53
            RTPrintf("%s, %d: " #val ": expected " fmt " got " fmt "\n", __FUNCTION__, __LINE__, (expect), (val)); \
59
54
        } \
60
55
    } while (0)
65
60
        type val = op; \
66
61
        if (val != (type)(expect)) \
67
62
        { \
68
 
            g_cErrors++; \
 
63
            RTTestIErrorInc(); \
69
64
            RTPrintf("%s, %d: " #op ": expected " fmt " got " fmt "\n", __FUNCTION__, __LINE__, (type)(expect), val); \
70
65
        } \
71
66
    } while (0)
553
548
}
554
549
 
555
550
 
556
 
#ifdef RT_ARCH_AMD64
557
 
static void tstASMAtomicXchgU128(void)
558
 
{
559
 
    struct
560
 
    {
561
 
        RTUINT128U  u128Dummy0;
562
 
        RTUINT128U  u128;
563
 
        RTUINT128U  u128Dummy1;
564
 
    } s;
565
 
    RTUINT128U u128Ret;
566
 
    RTUINT128U u128Arg;
567
 
 
568
 
 
569
 
    s.u128Dummy0.s.Lo = s.u128Dummy0.s.Hi = 0x1122334455667788;
570
 
    s.u128.s.Lo = 0;
571
 
    s.u128.s.Hi = 0;
572
 
    s.u128Dummy1 = s.u128Dummy0;
573
 
 
574
 
    u128Arg.s.Lo = 1;
575
 
    u128Arg.s.Hi = 0;
576
 
    u128Ret.u = ASMAtomicXchgU128(&s.u128.u, u128Arg.u);
577
 
    CHECKVAL(u128Ret.s.Lo, 0ULL, "%#llx");
578
 
    CHECKVAL(u128Ret.s.Hi, 0ULL, "%#llx");
579
 
    CHECKVAL(s.u128.s.Lo, 1ULL, "%#llx");
580
 
    CHECKVAL(s.u128.s.Hi, 0ULL, "%#llx");
581
 
 
582
 
    u128Arg.s.Lo = 0;
583
 
    u128Arg.s.Hi = 0;
584
 
    u128Ret.u = ASMAtomicXchgU128(&s.u128.u, u128Arg.u);
585
 
    CHECKVAL(u128Ret.s.Lo, 1ULL, "%#llx");
586
 
    CHECKVAL(u128Ret.s.Hi, 0ULL, "%#llx");
587
 
    CHECKVAL(s.u128.s.Lo, 0ULL, "%#llx");
588
 
    CHECKVAL(s.u128.s.Hi, 0ULL, "%#llx");
589
 
 
590
 
    u128Arg.s.Lo = ~0ULL;
591
 
    u128Arg.s.Hi = ~0ULL;
592
 
    u128Ret.u = ASMAtomicXchgU128(&s.u128.u, u128Arg.u);
593
 
    CHECKVAL(u128Ret.s.Lo, 0ULL, "%#llx");
594
 
    CHECKVAL(u128Ret.s.Hi, 0ULL, "%#llx");
595
 
    CHECKVAL(s.u128.s.Lo, ~0ULL, "%#llx");
596
 
    CHECKVAL(s.u128.s.Hi, ~0ULL, "%#llx");
597
 
 
598
 
 
599
 
    u128Arg.s.Lo = 0xfedcba0987654321ULL;
600
 
    u128Arg.s.Hi = 0x8897a6b5c4d3e2f1ULL;
601
 
    u128Ret.u = ASMAtomicXchgU128(&s.u128.u, u128Arg.u);
602
 
    CHECKVAL(u128Ret.s.Lo, ~0ULL, "%#llx");
603
 
    CHECKVAL(u128Ret.s.Hi, ~0ULL, "%#llx");
604
 
    CHECKVAL(s.u128.s.Lo, 0xfedcba0987654321ULL, "%#llx");
605
 
    CHECKVAL(s.u128.s.Hi, 0x8897a6b5c4d3e2f1ULL, "%#llx");
606
 
 
607
 
    CHECKVAL(s.u128Dummy0.s.Lo, 0x1122334455667788, "%#llx");
608
 
    CHECKVAL(s.u128Dummy0.s.Hi, 0x1122334455667788, "%#llx");
609
 
    CHECKVAL(s.u128Dummy1.s.Lo, 0x1122334455667788, "%#llx");
610
 
    CHECKVAL(s.u128Dummy1.s.Hi, 0x1122334455667788, "%#llx");
611
 
}
612
 
#endif
613
 
 
614
 
 
615
551
static void tstASMAtomicXchgPtr(void)
616
552
{
617
553
    void *pv = NULL;
751
687
        if (i32Rc != (rc)) \
752
688
        { \
753
689
            RTPrintf("%s, %d: FAILURE: %s -> %d expected %d\n", __FUNCTION__, __LINE__, #op, i32Rc, rc); \
754
 
            g_cErrors++; \
 
690
            RTTestIErrorInc(); \
755
691
        } \
756
692
        if (i32 != (val)) \
757
693
        { \
758
694
            RTPrintf("%s, %d: FAILURE: %s => i32=%d expected %d\n", __FUNCTION__, __LINE__, #op, i32, val); \
759
 
            g_cErrors++; \
 
695
            RTTestIErrorInc(); \
760
696
        } \
761
697
    } while (0)
762
698
    MYCHECK(ASMAtomicAddS32(&i32, 1),               10,             11);
780
716
        if (i32Rc != (rc)) \
781
717
        { \
782
718
            RTPrintf("%s, %d: FAILURE: %s -> %d expected %d\n", __FUNCTION__, __LINE__, #op, i32Rc, rc); \
783
 
            g_cErrors++; \
 
719
            RTTestIErrorInc(); \
784
720
        } \
785
721
        if (i32 != (rc)) \
786
722
        { \
787
723
            RTPrintf("%s, %d: FAILURE: %s => i32=%d expected %d\n", __FUNCTION__, __LINE__, #op, i32, rc); \
788
 
            g_cErrors++; \
 
724
            RTTestIErrorInc(); \
789
725
        } \
790
726
    } while (0)
791
727
    MYCHECK(ASMAtomicDecS32(&i32), 9);
875
811
        ||  Buf3.u64Magic2 != UINT64_C(0xffffffffffffffff))
876
812
    {
877
813
        RTPrintf("tstInlineAsm: ASMMemZeroPage violated one/both magic(s)!\n");
878
 
        g_cErrors++;
 
814
        RTTestIErrorInc();
879
815
    }
880
816
    for (unsigned i = 0; i < sizeof(Buf1.abPage); i++)
881
817
        if (Buf1.abPage[i])
882
818
        {
883
819
            RTPrintf("tstInlineAsm: ASMMemZeroPage didn't clear byte at offset %#x!\n", i);
884
 
            g_cErrors++;
 
820
            RTTestIErrorInc();
885
821
        }
886
822
    for (unsigned i = 0; i < sizeof(Buf2.abPage); i++)
887
823
        if (Buf2.abPage[i])
888
824
        {
889
825
            RTPrintf("tstInlineAsm: ASMMemZeroPage didn't clear byte at offset %#x!\n", i);
890
 
            g_cErrors++;
 
826
            RTTestIErrorInc();
891
827
        }
892
828
    for (unsigned i = 0; i < sizeof(Buf3.abPage); i++)
893
829
        if (Buf3.abPage[i])
894
830
        {
895
831
            RTPrintf("tstInlineAsm: ASMMemZeroPage didn't clear byte at offset %#x!\n", i);
896
 
            g_cErrors++;
 
832
            RTTestIErrorInc();
897
833
        }
898
834
}
899
835
 
900
836
 
 
837
void tstASMMemIsZeroPage(RTTEST hTest)
 
838
{
 
839
    RTTestSub(hTest, "ASMMemIsZeroPage");
 
840
 
 
841
    void *pvPage1 = RTTestGuardedAllocHead(hTest, PAGE_SIZE);
 
842
    void *pvPage2 = RTTestGuardedAllocTail(hTest, PAGE_SIZE);
 
843
    RTTESTI_CHECK_RETV(pvPage1 && pvPage2);
 
844
 
 
845
    memset(pvPage1, 0, PAGE_SIZE);
 
846
    memset(pvPage2, 0, PAGE_SIZE);
 
847
    RTTESTI_CHECK(ASMMemIsZeroPage(pvPage1));
 
848
    RTTESTI_CHECK(ASMMemIsZeroPage(pvPage2));
 
849
 
 
850
    memset(pvPage1, 0xff, PAGE_SIZE);
 
851
    memset(pvPage2, 0xff, PAGE_SIZE);
 
852
    RTTESTI_CHECK(!ASMMemIsZeroPage(pvPage1));
 
853
    RTTESTI_CHECK(!ASMMemIsZeroPage(pvPage2));
 
854
 
 
855
    memset(pvPage1, 0, PAGE_SIZE);
 
856
    memset(pvPage2, 0, PAGE_SIZE);
 
857
    for (unsigned off = 0; off < PAGE_SIZE; off++)
 
858
    {
 
859
        ((uint8_t *)pvPage1)[off] = 1;
 
860
        RTTESTI_CHECK(!ASMMemIsZeroPage(pvPage1));
 
861
        ((uint8_t *)pvPage1)[off] = 0;
 
862
 
 
863
        ((uint8_t *)pvPage2)[off] = 0x80;
 
864
        RTTESTI_CHECK(!ASMMemIsZeroPage(pvPage2));
 
865
        ((uint8_t *)pvPage2)[off] = 0;
 
866
    }
 
867
 
 
868
    RTTestSubDone(hTest);
 
869
}
 
870
 
 
871
 
901
872
void tstASMMemZero32(void)
902
873
{
903
874
    struct
927
898
        ||  Buf3.u64Magic2 != UINT64_C(0xffffffffffffffff))
928
899
    {
929
900
        RTPrintf("tstInlineAsm: ASMMemZero32 violated one/both magic(s)!\n");
930
 
        g_cErrors++;
 
901
        RTTestIErrorInc();
931
902
    }
932
903
    for (unsigned i = 0; i < RT_ELEMENTS(Buf1.abPage); i++)
933
904
        if (Buf1.abPage[i])
934
905
        {
935
906
            RTPrintf("tstInlineAsm: ASMMemZero32 didn't clear byte at offset %#x!\n", i);
936
 
            g_cErrors++;
 
907
            RTTestIErrorInc();
937
908
        }
938
909
    for (unsigned i = 0; i < RT_ELEMENTS(Buf2.abPage); i++)
939
910
        if (Buf2.abPage[i])
940
911
        {
941
912
            RTPrintf("tstInlineAsm: ASMMemZero32 didn't clear byte at offset %#x!\n", i);
942
 
            g_cErrors++;
 
913
            RTTestIErrorInc();
943
914
        }
944
915
    for (unsigned i = 0; i < RT_ELEMENTS(Buf3.abPage); i++)
945
916
        if (Buf3.abPage[i])
946
917
        {
947
918
            RTPrintf("tstInlineAsm: ASMMemZero32 didn't clear byte at offset %#x!\n", i);
948
 
            g_cErrors++;
 
919
            RTTestIErrorInc();
949
920
        }
950
921
}
951
922
 
991
962
        ||  Buf3.u64Magic2 != UINT64_C(0xffffffffffffffff))
992
963
    {
993
964
        RTPrintf("tstInlineAsm: ASMMemFill32 violated one/both magic(s)!\n");
994
 
        g_cErrors++;
 
965
        RTTestIErrorInc();
995
966
    }
996
967
    for (unsigned i = 0; i < RT_ELEMENTS(Buf1.au32Page); i++)
997
968
        if (Buf1.au32Page[i] != 0xdeadbeef)
998
969
        {
999
970
            RTPrintf("tstInlineAsm: ASMMemFill32 %#x: %#x exepcted %#x\n", i, Buf1.au32Page[i], 0xdeadbeef);
1000
 
            g_cErrors++;
 
971
            RTTestIErrorInc();
1001
972
        }
1002
973
    for (unsigned i = 0; i < RT_ELEMENTS(Buf2.au32Page); i++)
1003
974
        if (Buf2.au32Page[i] != 0xcafeff01)
1004
975
        {
1005
976
            RTPrintf("tstInlineAsm: ASMMemFill32 %#x: %#x exepcted %#x\n", i, Buf2.au32Page[i], 0xcafeff01);
1006
 
            g_cErrors++;
 
977
            RTTestIErrorInc();
1007
978
        }
1008
979
    for (unsigned i = 0; i < RT_ELEMENTS(Buf3.au32Page); i++)
1009
980
        if (Buf3.au32Page[i] != 0xf00dd00f)
1010
981
        {
1011
982
            RTPrintf("tstInlineAsm: ASMMemFill32 %#x: %#x exepcted %#x\n", i, Buf3.au32Page[i], 0xf00dd00f);
1012
 
            g_cErrors++;
 
983
            RTTestIErrorInc();
1013
984
        }
1014
985
}
1015
986
 
1226
1197
 
1227
1198
int main(int argc, char *argv[])
1228
1199
{
1229
 
    RTR3Init();
1230
 
    RTPrintf("tstInlineAsm: TESTING\n");
 
1200
    RTTEST hTest;
 
1201
    int rc = RTTestInitAndCreate("tstInlineAsm", &hTest);
 
1202
    if (rc)
 
1203
        return rc;
 
1204
    RTTestBanner(hTest);
1231
1205
 
1232
1206
    /*
1233
1207
     * Execute the tests.
1239
1213
    tstASMAtomicXchgU16();
1240
1214
    tstASMAtomicXchgU32();
1241
1215
    tstASMAtomicXchgU64();
1242
 
#ifdef RT_ARCH_AMD64
1243
 
    tstASMAtomicXchgU128();
1244
 
#endif
1245
1216
    tstASMAtomicXchgPtr();
1246
1217
    tstASMAtomicCmpXchgU32();
1247
1218
    tstASMAtomicCmpXchgU64();
1252
1223
    tstASMAtomicDecIncS32();
1253
1224
    tstASMAtomicAndOrU32();
1254
1225
    tstASMMemZeroPage();
 
1226
    tstASMMemIsZeroPage(hTest);
1255
1227
    tstASMMemZero32();
1256
1228
    tstASMMemFill32();
1257
1229
    tstASMMath();
1258
1230
    tstASMByteSwap();
1259
 
 
1260
1231
    tstASMBench();
1261
1232
 
1262
1233
    /*
1263
1234
     * Show the result.
1264
1235
     */
1265
 
    if (!g_cErrors)
1266
 
        RTPrintf("tstInlineAsm: SUCCESS\n", g_cErrors);
1267
 
    else
1268
 
        RTPrintf("tstInlineAsm: FAILURE - %d errors\n", g_cErrors);
1269
 
    return !!g_cErrors;
 
1236
    return RTTestSummaryAndDestroy(hTest);
1270
1237
}
1271
1238