Repository: microsoft/garnet
File: test/Garnet.test/GarnetBitmapTests.cs (C#)

Code before:
                }
            }
        }

        [Test, Order(6)]
        [Category("BITCOUNT")]
        [TestCase(false)]
        [TestCase(true)]
        public void BitmapSimpleBitCountTest(bool softwareFallback)
        {
            var configOptions = TestUtils.GetConfig();

            if (!softwareFallback)
            {
                Test();
            }
            else
            {
                var port = 7000;

                Dictionary<string, string> env = new()
                {
                    { "DOTNET_EnableHWIntrinsic", "0" }
                };

                using var p = TestUtils.StartProcess(typeof(Garnet.Program), port, env);
                configOptions = TestUtils.GetConfig([new IPEndPoint(IPAddress.Loopback, port)]);

                Test();

                try { p.Kill(); }
                catch { }
            }

            void Test()
            {
                using var redis = ConnectionMultiplexer.Connect(configOptions);
                var db = redis.GetDatabase(0);
                int maxBitmapLen = 1 << 12;
                int iter = 1024;
                long expectedCount = 0;
                string key = "SimpleBitCountTest";

                for (int i = 0; i < iter; i++)
                {
                    long offset = r.Next(1, maxBitmapLen);
                    bool set = !db.StringSetBit(key, offset, true);
                    expectedCount += set ? 1 : 0;
                }

                long count = db.StringBitCount(key);

Review comment (suggestion):
instead of using Garnet.Program, can you create your own test-only GarnetServer process that does not load all the extensions. We ideally don't want to pollute the main/ codebase with these InternalsVisibleTo. Or have to change GarnetServer.csproj for this.

Code after:
        [Test, Order(6)]
        [Category("BITCOUNT")]
        [TestCase(0, TestName = "BitmapSimpleBitCountTest(Hardware accelerated)")]
        [TestCase(1, TestName = "BitmapSimpleBitCountTest(Avx2 disabled)")]
        [TestCase(2, TestName = "BitmapSimpleBitCountTest(Software fallback)")]
        public void BitmapSimpleBitCountTest(int acceleration)
        {
            var configOptions = TestUtils.GetConfig();

            if (acceleration == 0)
            {
                SimpleBitCountTest();
            }
            else
            {
                Dictionary<string, string> env = [];

                if (acceleration == 1)
                {
                    if (!Avx2.IsSupported && Ssse3.IsSupported)
                        Assert.Ignore("Already tested by main path");

                    env.Add("DOTNET_EnableAVX2", "0");
                }
                else
                {
                    if (!Avx2.IsSupported && !Ssse3.IsSupported)
                        Assert.Ignore("Already tested by main path");

                    env.Add("DOTNET_EnableHWIntrinsic", "0");
                }

                using var p = new GarnetServerTestProcess(out configOptions, env);

                SimpleBitCountTest();
            }

            void SimpleBitCountTest()
            {
                using var redis = ConnectionMultiplexer.Connect(configOptions);
                var db = redis.GetDatabase(0);
                var maxBitmapLen = 1 << 12;
                var iter = 1024;
                var expectedCount = 0;
                var key = "SimpleBitCountTest";

                for (var i = 0; i < iter; i++)
                {
                    var offset = r.Next(1, maxBitmapLen);
                    var set = !db.StringSetBit(key, offset, true);
                    expectedCount += set ? 1 : 0;