Exemplo n.º 1
0
        private static void RunTests(String[] hashes, ValidationTestsSelection validationTestsSelection, Boolean qualityTests, Boolean speedTests)
        {
            Process process = Process.GetCurrentProcess();

            IntPtr affinityNew = (IntPtr)(1 << (Environment.ProcessorCount - 1));
            IntPtr affinityOld = process.ProcessorAffinity;

            process.ProcessorAffinity = affinityNew;

            Thread.BeginThreadAffinity();
            ProcessThread thread = NativeMethods.GetCurrentThread();

            if (thread != null)
            {
                thread.ProcessorAffinity = affinityNew;
            }

            for (Int32 i = 0; i < s_HashInfos.Length; ++i)
            {
                HashInfo hashInfo     = s_HashInfos[i];
                String   hashInfoName = hashInfo.Name;

                if (!hashes.Contains(hashInfoName))
                {
                    continue;
                }

                String title = $"# HASH: {hashInfoName} ({hashInfo.Length} Bits) #";
                String frame = new String('#', title.Length);

                Console.WriteLine(frame);
                Console.WriteLine(title);
                Console.WriteLine(frame);

                if (validationTestsSelection != ValidationTestsSelection.None)
                {
                    Console.WriteLine();
                    ValidationTests.VerificationTest(hashInfo);
                }

                if (validationTestsSelection == ValidationTestsSelection.All)
                {
                    Console.WriteLine();
                    ValidationTests.CombinationsTest(hashInfo);

                    Console.WriteLine();
                    ValidationTests.CyclicKeysTest(hashInfo);

                    Console.WriteLine();
                    ValidationTests.FlippedKeysTest(hashInfo);

                    Console.WriteLine();
                    ValidationTests.KeySetsTest(hashInfo);

                    Console.WriteLine();
                    ValidationTests.PaddedKeysTest(hashInfo);

                    Console.WriteLine();
                    ValidationTests.SparseKeysTest(hashInfo);

                    Console.WriteLine();
                    ValidationTests.TwoBytesTest(hashInfo);

                    Console.WriteLine();
                    ValidationTests.UniformKeysTest(hashInfo);

                    Console.WriteLine();
                    ValidationTests.WindowedKeysTest(hashInfo);

                    Console.WriteLine();
                    ValidationTests.WordsTest(hashInfo);
                }

                if (qualityTests)
                {
                    Console.WriteLine();
                    QualityTests.AvalancheTest(hashInfo);

                    Console.WriteLine();
                    QualityTests.BitIndependenceCriterionTest(hashInfo);

                    Console.WriteLine();
                    QualityTests.DifferentialTest(hashInfo);
                }

                if (speedTests)
                {
                    Console.WriteLine();
                    SpeedTests.BulkSpeedTest(hashInfo);

                    Console.WriteLine();
                    SpeedTests.ChunksSpeedTest(hashInfo);
                }

                Int32 hashInfoIndex = Array.IndexOf(hashes, hashInfoName);

                if (hashInfoIndex != (hashes.Length - 1))
                {
                    Console.WriteLine();
                }
            }

            process.ProcessorAffinity = affinityOld;

            if (thread != null)
            {
                thread.ProcessorAffinity = affinityOld;
            }

            Thread.EndThreadAffinity();
        }