Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qml test with large int values unstable in debug
QtWS25 Last Chance

Qml test with large int values unstable in debug

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmltestrunnerintegers
7 Posts 3 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vivi
    wrote on 7 Sept 2017, 07:10 last edited by vivi 9 Jul 2017, 09:59
    #1

    Hello,

    I am using qmltestrunner for some test application and came across a difference in behavior between release and debug build when dealing with large int values.

    The test is the following:
    tst_large-int.qml

    import QtQuick 2.5
    import QtTest 1.0
    
    TestCase
    {
        name: "large-int"
    
        function test_large_int(data)
        {
            var act = 0xA5000000;
            var exp = '2768240640';
            compare(act.toString(), exp);
        }
    }
    

    And the application used
    main.cpp -> ut-qml-large-int.exe

    #include <QQmlApplicationEngine>
    #include <QtQuickTest>
    
    int main(int argc, char *argv[])
    {
        return quick_test_main(argc, argv, "ut_qml", 0);
    }
    

    The command used to run the test is:

    ut-qml-large-int.exe -input tst_large-int.qml
    

    When the application is built in release and run with the command above, the test executes correctly every time.
    execution 1:

    ********* Start testing of ut_qml_large_int *********
    Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) release build; by GCC 5.3.0)
    PASS   : ut_qml_large_int::large-int::initTestCase()
    PASS   : ut_qml_large_int::large-int::test_large_int()
    PASS   : ut_qml_large_int::large-int::cleanupTestCase()
    Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 11ms
    ********* Finished testing of ut_qml_large_int *********
    

    execution 2:

    ********* Start testing of ut_qml_large_int *********
    Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) release build; by GCC 5.3.0)
    PASS   : ut_qml_large_int::large-int::initTestCase()
    PASS   : ut_qml_large_int::large-int::test_large_int()
    PASS   : ut_qml_large_int::large-int::cleanupTestCase()
    Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 11ms
    ********* Finished testing of ut_qml_large_int *********
    

    But when the same application is built in debug and run with the same command, the first execution is a success but all the following are failed.
    execution 1:

    ********* Start testing of ut_qml_large_int *********
    Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) debug build; by GCC 5.3.0)
    PASS   : ut_qml_large_int::large-int::initTestCase()
    PASS   : ut_qml_large_int::large-int::test_large_int()
    PASS   : ut_qml_large_int::large-int::cleanupTestCase()
    Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 13ms
    ********* Finished testing of ut_qml_large_int *********
    

    execution 2:

    ********* Start testing of ut_qml_large_int *********
    Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) debug build; by GCC 5.3.0)
    PASS   : ut_qml_large_int::large-int::initTestCase()
    FAIL!  : ut_qml_large_int::large-int::test_large_int() Compared values are not the same
       Actual   (): -5.386372713960645e+214
       Expected (): 2768240640
    ...\qtc_Desktop__f4d5050c-debug\install-root\ut-qml-large-int\bin\tst_large-int.qml(12) : failure location
    PASS   : ut_qml_large_int::large-int::cleanupTestCase()
    Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted, 14ms
    ********* Finished testing of ut_qml_large_int *********
    

    Is it something explicable?
    How to get everytime success in debug?

    J V 3 Replies Last reply 8 Sept 2017, 09:02
    0
    • T Offline
      T Offline
      timday
      wrote on 7 Sept 2017, 15:08 last edited by timday 9 Jul 2017, 15:09
      #2

      I'm slightly suspicious of the fact that 0xA5000000 = 2768240640 overflows a regular 32 bit signed integer. Whether that's taking you into "undefined behaviour" territory I have no idea. Possibly your issue is related to JS "numbers" sometimes being 32-bit ints and sometimes 64-bit floats though.

      V 1 Reply Last reply 8 Sept 2017, 08:53
      0
      • T timday
        7 Sept 2017, 15:08

        I'm slightly suspicious of the fact that 0xA5000000 = 2768240640 overflows a regular 32 bit signed integer. Whether that's taking you into "undefined behaviour" territory I have no idea. Possibly your issue is related to JS "numbers" sometimes being 32-bit ints and sometimes 64-bit floats though.

        V Offline
        V Offline
        vivi
        wrote on 8 Sept 2017, 08:53 last edited by
        #3

        @timday
        What make JS "numbers" using sometimes 32-bit ints or 64-bit floats?
        Is there a way to know which one will be used?

        Thanks.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          timday
          wrote on 8 Sept 2017, 09:02 last edited by
          #4

          Sorry don't know nearly enough about gnarly details of JS to comment further. You might find https://stackoverflow.com/questions/3885817/how-do-i-check-that-a-number-is-float-or-integer interesting though.

          One thing I have come across (in webdev world) is people writing things like var y=x|0 to force something to integer (the output of the bitwise | operator is guaranteed to be an int). Apparently tricks like that you can get big performance improvements in JS systems using JIT compilation by helping the compiler "know" what the types the code generated will be dealing with.

          1 Reply Last reply
          0
          • V vivi
            7 Sept 2017, 07:10

            Hello,

            I am using qmltestrunner for some test application and came across a difference in behavior between release and debug build when dealing with large int values.

            The test is the following:
            tst_large-int.qml

            import QtQuick 2.5
            import QtTest 1.0
            
            TestCase
            {
                name: "large-int"
            
                function test_large_int(data)
                {
                    var act = 0xA5000000;
                    var exp = '2768240640';
                    compare(act.toString(), exp);
                }
            }
            

            And the application used
            main.cpp -> ut-qml-large-int.exe

            #include <QQmlApplicationEngine>
            #include <QtQuickTest>
            
            int main(int argc, char *argv[])
            {
                return quick_test_main(argc, argv, "ut_qml", 0);
            }
            

            The command used to run the test is:

            ut-qml-large-int.exe -input tst_large-int.qml
            

            When the application is built in release and run with the command above, the test executes correctly every time.
            execution 1:

            ********* Start testing of ut_qml_large_int *********
            Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) release build; by GCC 5.3.0)
            PASS   : ut_qml_large_int::large-int::initTestCase()
            PASS   : ut_qml_large_int::large-int::test_large_int()
            PASS   : ut_qml_large_int::large-int::cleanupTestCase()
            Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 11ms
            ********* Finished testing of ut_qml_large_int *********
            

            execution 2:

            ********* Start testing of ut_qml_large_int *********
            Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) release build; by GCC 5.3.0)
            PASS   : ut_qml_large_int::large-int::initTestCase()
            PASS   : ut_qml_large_int::large-int::test_large_int()
            PASS   : ut_qml_large_int::large-int::cleanupTestCase()
            Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 11ms
            ********* Finished testing of ut_qml_large_int *********
            

            But when the same application is built in debug and run with the same command, the first execution is a success but all the following are failed.
            execution 1:

            ********* Start testing of ut_qml_large_int *********
            Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) debug build; by GCC 5.3.0)
            PASS   : ut_qml_large_int::large-int::initTestCase()
            PASS   : ut_qml_large_int::large-int::test_large_int()
            PASS   : ut_qml_large_int::large-int::cleanupTestCase()
            Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 13ms
            ********* Finished testing of ut_qml_large_int *********
            

            execution 2:

            ********* Start testing of ut_qml_large_int *********
            Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) debug build; by GCC 5.3.0)
            PASS   : ut_qml_large_int::large-int::initTestCase()
            FAIL!  : ut_qml_large_int::large-int::test_large_int() Compared values are not the same
               Actual   (): -5.386372713960645e+214
               Expected (): 2768240640
            ...\qtc_Desktop__f4d5050c-debug\install-root\ut-qml-large-int\bin\tst_large-int.qml(12) : failure location
            PASS   : ut_qml_large_int::large-int::cleanupTestCase()
            Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted, 14ms
            ********* Finished testing of ut_qml_large_int *********
            

            Is it something explicable?
            How to get everytime success in debug?

            J Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 8 Sept 2017, 09:02 last edited by
            #5

            @vivi
            mmh, have you seen this stackoverflow thread?
            compare seems like it would use bitwise operations. Could be the reason for the behavior.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • V vivi
              7 Sept 2017, 07:10

              Hello,

              I am using qmltestrunner for some test application and came across a difference in behavior between release and debug build when dealing with large int values.

              The test is the following:
              tst_large-int.qml

              import QtQuick 2.5
              import QtTest 1.0
              
              TestCase
              {
                  name: "large-int"
              
                  function test_large_int(data)
                  {
                      var act = 0xA5000000;
                      var exp = '2768240640';
                      compare(act.toString(), exp);
                  }
              }
              

              And the application used
              main.cpp -> ut-qml-large-int.exe

              #include <QQmlApplicationEngine>
              #include <QtQuickTest>
              
              int main(int argc, char *argv[])
              {
                  return quick_test_main(argc, argv, "ut_qml", 0);
              }
              

              The command used to run the test is:

              ut-qml-large-int.exe -input tst_large-int.qml
              

              When the application is built in release and run with the command above, the test executes correctly every time.
              execution 1:

              ********* Start testing of ut_qml_large_int *********
              Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) release build; by GCC 5.3.0)
              PASS   : ut_qml_large_int::large-int::initTestCase()
              PASS   : ut_qml_large_int::large-int::test_large_int()
              PASS   : ut_qml_large_int::large-int::cleanupTestCase()
              Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 11ms
              ********* Finished testing of ut_qml_large_int *********
              

              execution 2:

              ********* Start testing of ut_qml_large_int *********
              Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) release build; by GCC 5.3.0)
              PASS   : ut_qml_large_int::large-int::initTestCase()
              PASS   : ut_qml_large_int::large-int::test_large_int()
              PASS   : ut_qml_large_int::large-int::cleanupTestCase()
              Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 11ms
              ********* Finished testing of ut_qml_large_int *********
              

              But when the same application is built in debug and run with the same command, the first execution is a success but all the following are failed.
              execution 1:

              ********* Start testing of ut_qml_large_int *********
              Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) debug build; by GCC 5.3.0)
              PASS   : ut_qml_large_int::large-int::initTestCase()
              PASS   : ut_qml_large_int::large-int::test_large_int()
              PASS   : ut_qml_large_int::large-int::cleanupTestCase()
              Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 13ms
              ********* Finished testing of ut_qml_large_int *********
              

              execution 2:

              ********* Start testing of ut_qml_large_int *********
              Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) debug build; by GCC 5.3.0)
              PASS   : ut_qml_large_int::large-int::initTestCase()
              FAIL!  : ut_qml_large_int::large-int::test_large_int() Compared values are not the same
                 Actual   (): -5.386372713960645e+214
                 Expected (): 2768240640
              ...\qtc_Desktop__f4d5050c-debug\install-root\ut-qml-large-int\bin\tst_large-int.qml(12) : failure location
              PASS   : ut_qml_large_int::large-int::cleanupTestCase()
              Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted, 14ms
              ********* Finished testing of ut_qml_large_int *********
              

              Is it something explicable?
              How to get everytime success in debug?

              V Offline
              V Offline
              vivi
              wrote on 8 Sept 2017, 11:59 last edited by vivi 9 Aug 2017, 12:00
              #6

              the following test function pass at every execution in release and debug:

              function test_54bits_int(data)
              {
                  var act = 9007199254740992;
                  var exp = '9007199254740992';
                  compare(act.toString(), exp);
              }
              

              makes me puzzling...

              1 Reply Last reply
              0
              • V vivi
                7 Sept 2017, 07:10

                Hello,

                I am using qmltestrunner for some test application and came across a difference in behavior between release and debug build when dealing with large int values.

                The test is the following:
                tst_large-int.qml

                import QtQuick 2.5
                import QtTest 1.0
                
                TestCase
                {
                    name: "large-int"
                
                    function test_large_int(data)
                    {
                        var act = 0xA5000000;
                        var exp = '2768240640';
                        compare(act.toString(), exp);
                    }
                }
                

                And the application used
                main.cpp -> ut-qml-large-int.exe

                #include <QQmlApplicationEngine>
                #include <QtQuickTest>
                
                int main(int argc, char *argv[])
                {
                    return quick_test_main(argc, argv, "ut_qml", 0);
                }
                

                The command used to run the test is:

                ut-qml-large-int.exe -input tst_large-int.qml
                

                When the application is built in release and run with the command above, the test executes correctly every time.
                execution 1:

                ********* Start testing of ut_qml_large_int *********
                Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) release build; by GCC 5.3.0)
                PASS   : ut_qml_large_int::large-int::initTestCase()
                PASS   : ut_qml_large_int::large-int::test_large_int()
                PASS   : ut_qml_large_int::large-int::cleanupTestCase()
                Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 11ms
                ********* Finished testing of ut_qml_large_int *********
                

                execution 2:

                ********* Start testing of ut_qml_large_int *********
                Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) release build; by GCC 5.3.0)
                PASS   : ut_qml_large_int::large-int::initTestCase()
                PASS   : ut_qml_large_int::large-int::test_large_int()
                PASS   : ut_qml_large_int::large-int::cleanupTestCase()
                Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 11ms
                ********* Finished testing of ut_qml_large_int *********
                

                But when the same application is built in debug and run with the same command, the first execution is a success but all the following are failed.
                execution 1:

                ********* Start testing of ut_qml_large_int *********
                Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) debug build; by GCC 5.3.0)
                PASS   : ut_qml_large_int::large-int::initTestCase()
                PASS   : ut_qml_large_int::large-int::test_large_int()
                PASS   : ut_qml_large_int::large-int::cleanupTestCase()
                Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 13ms
                ********* Finished testing of ut_qml_large_int *********
                

                execution 2:

                ********* Start testing of ut_qml_large_int *********
                Config: Using QtTest library 5.8.0, Qt 5.8.0 (i386-little_endian-ilp32 shared (dynamic) debug build; by GCC 5.3.0)
                PASS   : ut_qml_large_int::large-int::initTestCase()
                FAIL!  : ut_qml_large_int::large-int::test_large_int() Compared values are not the same
                   Actual   (): -5.386372713960645e+214
                   Expected (): 2768240640
                ...\qtc_Desktop__f4d5050c-debug\install-root\ut-qml-large-int\bin\tst_large-int.qml(12) : failure location
                PASS   : ut_qml_large_int::large-int::cleanupTestCase()
                Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted, 14ms
                ********* Finished testing of ut_qml_large_int *********
                

                Is it something explicable?
                How to get everytime success in debug?

                V Offline
                V Offline
                vivi
                wrote on 8 Sept 2017, 12:17 last edited by
                #7

                Seems I got a solution but no explication.

                This test is passing everytime in release and debug...

                function test_large_int_add0(data)
                {
                    var act = 0xA5000000 + 0;
                    var exp = '2768240640';
                    compare(act.toString(), exp);
                }
                
                1 Reply Last reply
                0

                3/7

                8 Sept 2017, 08:53

                • Login

                • Login or register to search.
                3 out of 7
                • First post
                  3/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved