Exemple #1
0
        /*
         *  Calling shutdown is a more forcefull way of
         *  killing off LuckyMe and Haggle.
         *  Returns: true if the caller should call Application.exit()
         *  or, false if Application.exit() will be called automatically.
         * */
        public static bool shutdown()
        {
            bool retval = true;

            setTestStage(TestStage.SHUTDOWN);

            if (LuckyMeLib.isHaggleRunning() && LuckyMeLib.isLuckyMeRunning())
            {
                Debug.WriteLine("shutdown: Trying to stop LuckyMe and Haggle");
                LuckyMeLib.stopLuckyMe(1);
                retval = false;
            }
            else
            {
                if (LuckyMeLib.isLuckyMeRunning())
                {
                    Debug.WriteLine("shutdown: Trying to stop LuckyMe");
                    LuckyMeLib.stopLuckyMe(0);
                }
                if (LuckyMeLib.isHaggleRunning())
                {
                    Debug.WriteLine("shutdown: Trying to stop Haggle");
                    LuckyMeLib.stopHaggle();
                }
            }

            Debug.WriteLine("shutdown: completed...");
            return(retval);
        }
Exemple #2
0
        public static bool stopTest()
        {
            bool retval = true;             // be optimistic :)

            if (testStage != TestStage.RUNNING)
            {
                Debug.WriteLine("Cannot stop test since test stage=" + testStageString());
                return(false);
            }

            mCallTimer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);

            setTestStage(TestStage.STOPPING);

            if (LuckyMeLib.isLuckyMeRunning())
            {
                if (LuckyMeLib.isHaggleRunning())
                {
                    int res = LuckyMeLib.stopLuckyMe(1);

                    Debug.WriteLine("stopLuckyMe() returned " + res);

                    if (res < 0)
                    {
                        Debug.WriteLine("stopTest(): stopLuckyMe failed");

                        if (LuckyMeLib.isTestRunning())
                        {
                            setTestStage(TestStage.RUNNING);
                        }
                        else
                        {
                            // Set not running although test stop failed
                            setTestStage(TestStage.NOT_RUNNING);
                            return(true);
                        }

                        return(false);
                    }

                    setTestStage(TestStage.STOPPING);
                }
                else
                {
                    Debug.WriteLine("stopTest(): Haggle was not running");
                    int res = LuckyMeLib.stopLuckyMe(0);
                    // Haggle was not running so we cannot expect a shutdown callback
                    // -> set NOT_RUNNING immediately
                    setTestStage(TestStage.NOT_RUNNING);
                }
            }
            else
            {
                if (LuckyMeLib.isHaggleRunning())
                {
                    int res = LuckyMeLib.stopHaggle();

                    if (res == 1)
                    {
                        Debug.WriteLine("stopTest(): Haggle stopped");
                    }
                    else if (res == -1)
                    {
                        Debug.WriteLine("stopTest(): Could not stop Haggle, no Haggle handle");
                    }
                    else
                    {
                        Debug.WriteLine("stopTest(): Could not stop Haggle, not running");
                    }
                }

                setTestStage(TestStage.NOT_RUNNING);
            }
            return(retval);
        }
Exemple #3
0
        public static bool startTest()
        {
            if (testStage != TestStage.NOT_RUNNING)
            {
                return(false);
            }

            // Reset counters
            numDataObjectsGenerated = 0;

            setTestStage(TestStage.STARTING);

            if (!startHaggle())
            {
                setTestStage(TestStage.NOT_RUNNING);
                return(false);
            }

            // Start LuckyMe thread
            if (!LuckyMeLib.isLuckyMeRunning())
            {
                int res = LuckyMeLib.startLuckyMe();

                if (res < 0)
                {
                    Debug.WriteLine("Error: Could not start LuckyMe!");
                    setTestStage(TestStage.NOT_RUNNING);
                    return(false);
                }

                // Check again that LuckyMe and the Haggle event loop is running
                if (!LuckyMeLib.isLuckyMeRunning())
                {
                    Debug.WriteLine("Error: LuckyMe not running after start!");
                    setTestStage(TestStage.NOT_RUNNING);
                    return(false);
                }
            }
            else
            {
                Debug.WriteLine("LuckyMe already running");
            }

            Thread.Sleep(2000);

            if (!LuckyMeLib.isTestRunning())
            {
                Debug.WriteLine("Starting LuckyMe test loop");

                int res = LuckyMeLib.startTest();

                if (res < 0)
                {
                    Debug.WriteLine("Error: Could not start LuckyMe test loop!");
                    setTestStage(TestStage.NOT_RUNNING);
                    LuckyMeLib.stopHaggle();
                    return(false);
                }
            }
            else
            {
                Debug.WriteLine("LuckyMe test already running");
            }

            setTestStage(TestStage.RUNNING);

            return(true);
        }