Esempio n. 1
0
        public void SessionTest4()
        {
            using var session1 = fht.NewSession(new Functions());
            using var session2 = fht.NewSession(new Functions());
            var t1 = Task.CompletedTask.ContinueWith((t) =>
            {
                InputStruct input   = default;
                OutputStruct output = default;

                var key1 = new KeyStruct {
                    kfield1 = 14, kfield2 = 15
                };
                var value1 = new ValueStruct {
                    vfield1 = 24, vfield2 = 25
                };

                session1.Upsert(ref key1, ref value1, Empty.Default, 0);
                var status = session1.Read(ref key1, ref input, ref output, Empty.Default, 0);

                if (status.IsPending)
                {
                    session1.CompletePendingWithOutputs(out var outputs, wait: true);
                    (status, output) = GetSinglePendingResult(outputs);
                }

                Assert.IsTrue(status.Found);
                Assert.AreEqual(value1.vfield1, output.value.vfield1);
                Assert.AreEqual(value1.vfield2, output.value.vfield2);
            });

            var t2 = Task.CompletedTask.ContinueWith((t) =>
            {
                InputStruct input   = default;
                OutputStruct output = default;

                var key2 = new KeyStruct {
                    kfield1 = 15, kfield2 = 16
                };
                var value2 = new ValueStruct {
                    vfield1 = 25, vfield2 = 26
                };

                session2.Upsert(ref key2, ref value2, Empty.Default, 0);

                var status = session2.Read(ref key2, ref input, ref output, Empty.Default, 0);

                if (status.IsPending)
                {
                    session2.CompletePendingWithOutputs(out var outputs, wait: true);
                    (status, output) = GetSinglePendingResult(outputs);
                }

                Assert.IsTrue(status.Found);
                Assert.AreEqual(value2.vfield1, output.value.vfield1);
                Assert.AreEqual(value2.vfield2, output.value.vfield2);
            });

            t1.Wait();
            t2.Wait();
        }
Esempio n. 2
0
        public void NativeInMemWriteRead([Values] TestUtils.DeviceType deviceType)
        {
            Setup(128, new LogSettings {
                PageSizeBits = 10, MemorySizeBits = 12, SegmentSizeBits = 22
            }, deviceType);
            uContext.ResumeThread();

            try
            {
                InputStruct  input  = default;
                OutputStruct output = default;

                var key1 = new KeyStruct {
                    kfield1 = 13, kfield2 = 14
                };
                var value = new ValueStruct {
                    vfield1 = 23, vfield2 = 24
                };

                uContext.Upsert(ref key1, ref value, Empty.Default, 0);
                var status = uContext.Read(ref key1, ref input, ref output, Empty.Default, 0);

                AssertCompleted(new (StatusCode.Found), status);
                Assert.AreEqual(value.vfield1, output.value.vfield1);
                Assert.AreEqual(value.vfield2, output.value.vfield2);
            }
            finally
            {
                uContext.SuspendThread();
            }
        }
Esempio n. 3
0
        public void SessionTest1()
        {
            using var session = fht.NewSession(new Functions());
            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            session.Upsert(ref key1, ref value, Empty.Default, 0);
            var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);

            if (status == Status.PENDING)
            {
                session.CompletePending(true);
            }
            else
            {
                Assert.IsTrue(status == Status.OK);
            }

            Assert.IsTrue(output.value.vfield1 == value.vfield1);
            Assert.IsTrue(output.value.vfield2 == value.vfield2);
        }
Esempio n. 4
0
        public void ReadWithoutInput([Values] TestUtils.DeviceType deviceType)
        {
            Setup(128, new LogSettings {
                MemorySizeBits = 22, SegmentSizeBits = 22, PageSizeBits = 10
            }, deviceType);
            uContext.ResumeThread();

            try
            {
                OutputStruct output = default;

                var key1 = new KeyStruct {
                    kfield1 = 13, kfield2 = 14
                };
                var value = new ValueStruct {
                    vfield1 = 23, vfield2 = 24
                };

                uContext.Upsert(ref key1, ref value, Empty.Default, 0);
                var status = uContext.Read(ref key1, ref output, Empty.Default, 99);
                AssertCompleted(new(StatusCode.Found), status);

                // Verify the read data
                Assert.AreEqual(value.vfield1, output.value.vfield1);
                Assert.AreEqual(value.vfield2, output.value.vfield2);
                Assert.AreEqual(key1.kfield1, 13);
                Assert.AreEqual(key1.kfield2, 14);
            }
            finally
            {
                uContext.SuspendThread();
            }
        }
Esempio n. 5
0
        public void SessionTest1()
        {
            using var session = fht.NewSession(new Functions());
            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            session.Upsert(ref key1, ref value, Empty.Default, 0);
            var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);

            if (status.IsPending)
            {
                session.CompletePendingWithOutputs(out var outputs, wait: true);
                (status, output) = GetSinglePendingResult(outputs);
            }

            Assert.IsTrue(status.Found);
            Assert.AreEqual(value.vfield1, output.value.vfield1);
            Assert.AreEqual(value.vfield2, output.value.vfield2);
        }
Esempio n. 6
0
        public void SessionTest3()
        {
            using var session = fht.NewSession(new Functions());
            Task.CompletedTask.ContinueWith((t) =>
            {
                InputStruct input   = default;
                OutputStruct output = default;

                var key1 = new KeyStruct {
                    kfield1 = 13, kfield2 = 14
                };
                var value = new ValueStruct {
                    vfield1 = 23, vfield2 = 24
                };

                session.Upsert(ref key1, ref value, Empty.Default, 0);
                var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);

                if (status == Status.PENDING)
                {
                    session.CompletePending(true);
                }
                else
                {
                    Assert.AreEqual(Status.OK, status);
                }

                Assert.AreEqual(value.vfield1, output.value.vfield1);
                Assert.AreEqual(value.vfield2, output.value.vfield2);
            }).Wait();
        }
Esempio n. 7
0
        //excel operation
        public string ExportSingleData2Excel(string filePath, OutputStruct maintainManageInfo)
        {
            OutputStruct outputStruct = new OutputStruct()
            {
                ToolModeName   = maintainManageInfo.ToolModeName,
                ToolSerialName = maintainManageInfo.ToolSerialName,
                SendFixTime    = maintainManageInfo.SendFixTime,
                Status         = maintainManageInfo.Status,
                Detail         = maintainManageInfo.Detail
            };
            int affected = 0;

            try
            {
                affected = maintainManageInfoService.CreateMaintainManageInfoExcelTable(filePath);
                //if (affected < 1) return "创建导出文件失败";
            }
            catch (Exception ex)
            {
                Console.WriteLine($"CreateMaintainManageInfoExcelTable fail: {ex.Message}");
            }

            affected = maintainManageInfoService.InsertMaintainManageInfo2ExcelTable(filePath, outputStruct);
            if (affected < 1)
            {
                return("导出数据失败");
            }
            return("导出数据成功");
        }
Esempio n. 8
0
        GameObject CreateBatchGos(string desc, OutputStruct billboard, OutputStruct tri)
        {
            GameObject batchGo = null;

            // Billboad Grass mesh
            for (int i = 0; i < billboard.GetCount(); i++)
            {
                GameObject go = new GameObject();
                if (batchGo != null)
                {
                    go.transform.parent = batchGo.transform;
                    go.name             = "Billboard";
                }
                else
                {
                    batchGo = go;
                    go.name = desc + " Billboard";
                }

                MeshFilter mf = go.AddComponent <MeshFilter>();
                go.AddComponent <MeshRenderer>().material = grassMat;

                mf.mesh.vertices  = billboard.mVerts[i];
                mf.mesh.triangles = billboard.mIndices[i];
                mf.mesh.normals   = billboard.mNorms[i];
                mf.mesh.uv        = billboard.mUVs[i];
                mf.mesh.uv2       = billboard.mUV2s[i];
                mf.mesh.colors32  = billboard.mColors32[i];
            }


            // Tri-angle Grass mesh
            for (int i = 0; i < tri.GetCount(); i++)
            {
                GameObject go = new GameObject();
                if (batchGo != null)
                {
                    go.transform.parent = batchGo.transform;
                    go.name             = "Tri-angle";
                }
                else
                {
                    batchGo = go;
                    go.name = desc + " Tri-angle";
                }

                MeshFilter mf = go.AddComponent <MeshFilter>();
                //mf.renderer.material = GrassMgr.Instance.m_GrassMat;
                go.AddComponent <MeshRenderer>().material = triMat;

                mf.mesh.vertices  = tri.mVerts[i];
                mf.mesh.triangles = tri.mIndices[i];
                mf.mesh.normals   = tri.mNorms[i];
                mf.mesh.uv        = tri.mUVs[i];
                mf.mesh.uv2       = tri.mUV2s[i];
                mf.mesh.colors32  = tri.mColors32[i];
            }

            return(batchGo);
        }
Esempio n. 9
0
        public void SessionTest2()
        {
            using (var session1 = fht.NewSession())
                using (var session2 = fht.NewSession())
                {
                    InputStruct  input  = default(InputStruct);
                    OutputStruct output = default(OutputStruct);

                    var key1 = new KeyStruct {
                        kfield1 = 14, kfield2 = 15
                    };
                    var value1 = new ValueStruct {
                        vfield1 = 24, vfield2 = 25
                    };
                    var key2 = new KeyStruct {
                        kfield1 = 15, kfield2 = 16
                    };
                    var value2 = new ValueStruct {
                        vfield1 = 25, vfield2 = 26
                    };

                    session1.Upsert(ref key1, ref value1, Empty.Default, 0);
                    session2.Upsert(ref key2, ref value2, Empty.Default, 0);

                    var status = session1.Read(ref key1, ref input, ref output, Empty.Default, 0);

                    if (status == Status.PENDING)
                    {
                        session1.CompletePending(true);
                    }
                    else
                    {
                        Assert.IsTrue(status == Status.OK);
                    }

                    Assert.IsTrue(output.value.vfield1 == value1.vfield1);
                    Assert.IsTrue(output.value.vfield2 == value1.vfield2);

                    status = session2.Read(ref key2, ref input, ref output, Empty.Default, 0);

                    if (status == Status.PENDING)
                    {
                        session2.CompletePending(true);
                    }
                    else
                    {
                        Assert.IsTrue(status == Status.OK);
                    }

                    Assert.IsTrue(output.value.vfield1 == value2.vfield1);
                    Assert.IsTrue(output.value.vfield2 == value2.vfield2);
                }
        }
Esempio n. 10
0
        public void SessionTest2()
        {
            using var session1 = fht.NewSession(new Functions());
            using var session2 = fht.NewSession(new Functions());
            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 14, kfield2 = 15
            };
            var value1 = new ValueStruct {
                vfield1 = 24, vfield2 = 25
            };
            var key2 = new KeyStruct {
                kfield1 = 15, kfield2 = 16
            };
            var value2 = new ValueStruct {
                vfield1 = 25, vfield2 = 26
            };

            session1.Upsert(ref key1, ref value1, Empty.Default, 0);
            session2.Upsert(ref key2, ref value2, Empty.Default, 0);

            var status = session1.Read(ref key1, ref input, ref output, Empty.Default, 0);

            if (status == Status.PENDING)
            {
                session1.CompletePending(true);
            }
            else
            {
                Assert.AreEqual(Status.OK, status);
            }

            Assert.AreEqual(value1.vfield1, output.value.vfield1);
            Assert.AreEqual(value1.vfield2, output.value.vfield2);

            status = session2.Read(ref key2, ref input, ref output, Empty.Default, 0);

            if (status == Status.PENDING)
            {
                session2.CompletePending(true);
            }
            else
            {
                Assert.AreEqual(Status.OK, status);
            }

            Assert.AreEqual(value2.vfield1, output.value.vfield1);
            Assert.AreEqual(value2.vfield2, output.value.vfield2);
        }
Esempio n. 11
0
    public static void Transfer(int VerticesPerSide, int VerticesPerSideWithBorder, OutputStruct[] patchPreOutput, out OutputStruct[] patchOutput)
    {
        patchOutput = new OutputStruct[VerticesPerSide * VerticesPerSide];

        Vector3i id = Vector3i.Zero;

        for (int x = id.X; x < VerticesPerSideWithBorder; x++)
        {
            for (int y = id.Y; y < VerticesPerSideWithBorder; y++)
            {
                int inBuffOffset  = (id.X + 1) + (id.Y + 1) * VerticesPerSideWithBorder;
                int outBuffOffset = id.X + id.Y * VerticesPerSide;

                patchOutput[outBuffOffset] = patchPreOutput[inBuffOffset];
            }
        }
    }
Esempio n. 12
0
        /// <summary>
        /// Read buffer, of specified size, at physical address
        /// </summary>
        /// <returns>Success</returns>
        public bool ReadPhysicalAddress(ulong lpAddress, ulong lpBuffer, ulong lLength)
        {
            InputReadStruct input  = new InputReadStruct();
            OutputStruct    output = new OutputStruct();

            if (lpAddress == 0 || lpBuffer == 0)
            {
                return(false);
            }

            input.AddressHigh = (uint)HIDWORD(lpAddress);
            input.AddressLow  = (uint)LODWORD(lpAddress);
            input.Length      = (uint)lLength;
            input.BufferHigh  = (uint)HIDWORD(lpBuffer);
            input.BufferLow   = (uint)LODWORD(lpBuffer);

            UInt32 io = 0;

            return(Nt.DeviceIoControl(g_DeviceHandle, IOCTL_ReadPhysicalAddress, &input, (uint)Marshal.SizeOf(typeof(InputReadStruct)), &output, (uint)Marshal.SizeOf(typeof(OutputStruct)), &io, 0));
        }
Esempio n. 13
0
        /// <summary>
        /// Write buffer, of specified size, at physical address
        /// </summary>
        /// <returns>Success</returns>
        public bool WritePhysicalAddress(ulong address, ulong buf, ulong len)
        {
            if (len % 4 != 0 || len == 0)
            {
                throw new Exception("The CPU-Z driver can only write lengths that are aligned to 4 bytes (4, 8, 12, 16, etc)");
            }

            InputWriteStruct in_mem  = new InputWriteStruct();
            OutputStruct     out_mem = new OutputStruct();

            if (address == 0 || buf == 0)
            {
                return(false);
            }

            UInt32 io = 0;

            if (len == 4)
            {
                in_mem.AddressHigh = (uint)HIDWORD(address);
                in_mem.AddressLow  = (uint)LODWORD(address);
                in_mem.Value       = *(uint *)buf;

                return(Nt.DeviceIoControl(g_DeviceHandle, IOCTL_WritePhysicalAddress, &in_mem, (uint)Marshal.SizeOf(typeof(InputWriteStruct)), &out_mem, (uint)Marshal.SizeOf(typeof(OutputStruct)), &io, 0));
            }
            else
            {
                for (uint i = 0; i < len / 4; i++)
                {
                    in_mem.AddressHigh = (uint)HIDWORD(address + 4 * i);
                    in_mem.AddressLow  = (uint)LODWORD(address + 4 * i);
                    in_mem.Value       = ((uint *)buf)[i];
                    if (!Nt.DeviceIoControl(g_DeviceHandle, IOCTL_WritePhysicalAddress, &in_mem, (uint)Marshal.SizeOf(typeof(InputWriteStruct)), &out_mem, (uint)Marshal.SizeOf(typeof(OutputStruct)), &io, 0))
                    {
                        return(false);
                    }
                }
                return(true);
            }
        }
Esempio n. 14
0
    public static void HeightMain(QuadGenerationConstants constants, int nVerticesPerSideWithBorder, out OutputStruct[] patchPreOutput)
    {
        patchPreOutput = new OutputStruct[nVerticesPerSideWithBorder * nVerticesPerSideWithBorder];

        Vector3i id = Vector3i.Zero;

        for (int x = id.X; x < nVerticesPerSideWithBorder; x++)
        {
            for (int y = id.Y; y < nVerticesPerSideWithBorder; y++)
            {
                int outBuffOffset = id.X + id.Y * nVerticesPerSideWithBorder;

                Vector3 cubeCoord = CubeCoord(constants, nVerticesPerSideWithBorder, id, (int)constants.borderMod.x, constants.spacing);

                Vector3 patchCenter          = constants.patchCubeCenter.normalized * constants.planetRadius;
                Vector3 patchNormalizedCoord = cubeCoord.normalized;

                Vector3 patchCoord                 = constants.planetRadius * patchNormalizedCoord;
                Vector3 patchCoordCentered         = patchCoord - patchCenter;
                Vector3 patchCubeCoordCentered     = patchNormalizedCoord;
                Vector3 patchCubeCoordCenteredFlat = patchNormalizedCoord;

                float noise = 1;

                float height = noise * constants.terrainMaxHeight;

                patchCoordCentered         += patchNormalizedCoord * height;
                patchCubeCoordCentered     += patchNormalizedCoord * height;
                patchCubeCoordCenteredFlat += patchNormalizedCoord;

                Vector4 output     = new Vector4(patchCoordCentered.x, patchCoordCentered.y, patchCoordCentered.z, 0.0f);
                Vector4 cubeOutput = new Vector4(patchCubeCoordCentered.x, patchCubeCoordCentered.y, patchCubeCoordCentered.z, 0.0f);

                patchPreOutput[outBuffOffset].noise        = noise;
                patchPreOutput[outBuffOffset].patchCenter  = patchCenter;
                patchPreOutput[outBuffOffset].position     = output;
                patchPreOutput[outBuffOffset].cubePosition = cubeOutput;
            }
        }
    }
Esempio n. 15
0
        public void ReadAtAddressReadFlagsNone()
        {
            // Just functional test of ReadFlag so one device is enough
            deviceType = TestUtils.DeviceType.MLSD;

            Setup(128, new LogSettings {
                MemorySizeBits = 29
            }, deviceType);
            uContext.ResumeThread();

            try
            {
                InputStruct  input  = default;
                OutputStruct output = default;

                var key1 = new KeyStruct {
                    kfield1 = 13, kfield2 = 14
                };
                var value = new ValueStruct {
                    vfield1 = 23, vfield2 = 24
                };
                ReadOptions readOptions = new() { StartAddress = fht.Log.BeginAddress };

                uContext.Upsert(ref key1, ref value, Empty.Default, 0);
                var status = uContext.ReadAtAddress(ref input, ref output, ref readOptions, Empty.Default, 0);
                AssertCompleted(new(StatusCode.Found), status);

                Assert.AreEqual(value.vfield1, output.value.vfield1);
                Assert.AreEqual(value.vfield2, output.value.vfield2);
                Assert.AreEqual(key1.kfield1, 13);
                Assert.AreEqual(key1.kfield2, 14);
            }
            finally
            {
                uContext.SuspendThread();
            }
        }
Esempio n. 16
0
        private OutputStruct[] GetMaintainManageInfoFromGrid()
        {
            OutputStruct[]      maintainManageInfo = new OutputStruct[] { };
            List <OutputStruct> ktls = maintainManageInfo.ToList();
            //遍历 DataGridView 所有行
            int row  = dataGridView1.Rows.Count;          //得到总行数
            int cell = dataGridView1.Rows[0].Cells.Count; //得到总列数

            for (int i = 0; i < row; i++)                 //得到总行数并在之内循环
            {
                if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].EditedFormattedValue))
                {
                    ktls.Add(new OutputStruct
                    {
                        ToolModeName   = dataGridView1.Rows[i].Cells[1].Value.ToString(),
                        ToolSerialName = dataGridView1.Rows[i].Cells[2].Value.ToString(),
                        SendFixTime    = dataGridView1.Rows[i].Cells[3].Value.ToString(),
                        Status         = dataGridView1.Rows[i].Cells[4].Value.ToString(),
                        Detail         = dataGridView1.Rows[i].Cells[5].Value.ToString(),
                    });
                }
            }
            return(ktls.ToArray());
        }
Esempio n. 17
0
        public void ReadWithoutSerialID()
        {
            // Just checking without Serial ID so one device type is enough
            deviceType = TestUtils.DeviceType.MLSD;

            Setup(128, new LogSettings {
                MemorySizeBits = 29
            }, deviceType);
            uContext.ResumeThread();

            try
            {
                InputStruct  input  = default;
                OutputStruct output = default;

                var key1 = new KeyStruct {
                    kfield1 = 13, kfield2 = 14
                };
                var value = new ValueStruct {
                    vfield1 = 23, vfield2 = 24
                };

                uContext.Upsert(ref key1, ref value, Empty.Default, 0);
                var status = uContext.Read(ref key1, ref input, ref output, Empty.Default);
                AssertCompleted(new(StatusCode.Found), status);

                Assert.AreEqual(value.vfield1, output.value.vfield1);
                Assert.AreEqual(value.vfield2, output.value.vfield2);
                Assert.AreEqual(key1.kfield1, 13);
                Assert.AreEqual(key1.kfield2, 14);
            }
            finally
            {
                uContext.SuspendThread();
            }
        }
Esempio n. 18
0
        public void SessionTest4()
        {
            using var session1 = fht.NewSession(new Functions());
            using var session2 = fht.NewSession(new Functions());
            var t1 = Task.CompletedTask.ContinueWith((t) =>
            {
                InputStruct input   = default;
                OutputStruct output = default;

                var key1 = new KeyStruct {
                    kfield1 = 14, kfield2 = 15
                };
                var value1 = new ValueStruct {
                    vfield1 = 24, vfield2 = 25
                };

                session1.Upsert(ref key1, ref value1, Empty.Default, 0);
                var status = session1.Read(ref key1, ref input, ref output, Empty.Default, 0);

                if (status == Status.PENDING)
                {
                    session1.CompletePending(true);
                }
                else
                {
                    Assert.IsTrue(status == Status.OK);
                }

                Assert.IsTrue(output.value.vfield1 == value1.vfield1);
                Assert.IsTrue(output.value.vfield2 == value1.vfield2);
            });

            var t2 = Task.CompletedTask.ContinueWith((t) =>
            {
                InputStruct input   = default;
                OutputStruct output = default;

                var key2 = new KeyStruct {
                    kfield1 = 15, kfield2 = 16
                };
                var value2 = new ValueStruct {
                    vfield1 = 25, vfield2 = 26
                };

                session2.Upsert(ref key2, ref value2, Empty.Default, 0);

                var status = session2.Read(ref key2, ref input, ref output, Empty.Default, 0);

                if (status == Status.PENDING)
                {
                    session2.CompletePending(true);
                }
                else
                {
                    Assert.IsTrue(status == Status.OK);
                }

                Assert.IsTrue(output.value.vfield1 == value2.vfield1);
                Assert.IsTrue(output.value.vfield2 == value2.vfield2);
            });

            t1.Wait();
            t2.Wait();
        }
Esempio n. 19
0
 public static void Init()
 {
     s_Output = new OutputStruct();
     s_Output.Init();
 }
Esempio n. 20
0
        public void NativeInMemWriteReadDelete2()
        {
            // Just set this one since Write Read Delete already does all four devices
            deviceType = TestUtils.DeviceType.MLSD;

            const int count = 10;

            // Setup(128, new LogSettings { MemorySizeBits = 22, SegmentSizeBits = 22, PageSizeBits = 10 }, deviceType);
            Setup(128, new LogSettings {
                MemorySizeBits = 29
            }, deviceType);
            uContext.ResumeThread();

            try
            {
                InputStruct  input  = default;
                OutputStruct output = default;

                for (int i = 0; i < 10 * count; i++)
                {
                    var key1 = new KeyStruct {
                        kfield1 = i, kfield2 = 14
                    };
                    var value = new ValueStruct {
                        vfield1 = i, vfield2 = 24
                    };

                    uContext.Upsert(ref key1, ref value, Empty.Default, 0);
                }

                for (int i = 0; i < 10 * count; i++)
                {
                    var key1 = new KeyStruct {
                        kfield1 = i, kfield2 = 14
                    };
                    uContext.Delete(ref key1, Empty.Default, 0);
                }

                for (int i = 0; i < 10 * count; i++)
                {
                    var key1 = new KeyStruct {
                        kfield1 = i, kfield2 = 14
                    };
                    var value = new ValueStruct {
                        vfield1 = i, vfield2 = 24
                    };

                    var status = uContext.Read(ref key1, ref input, ref output, Empty.Default, 0);
                    AssertCompleted(new(StatusCode.NotFound), status);

                    uContext.Upsert(ref key1, ref value, Empty.Default, 0);
                }

                for (int i = 0; i < 10 * count; i++)
                {
                    var key1 = new KeyStruct {
                        kfield1 = i, kfield2 = 14
                    };
                    var status = uContext.Read(ref key1, ref input, ref output, Empty.Default, 0);
                    AssertCompleted(new(StatusCode.Found), status);
                }
            }
            finally
            {
                uContext.SuspendThread();
            }
        }
Esempio n. 21
0
        public void NativeDiskWriteReadCache()
        {
            using var session = fht.NewSession(new Functions());

            InputStruct input = default;

            for (int i = 0; i < 2000; i++)
            {
                var key1 = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };
                session.Upsert(ref key1, ref value, Empty.Default, 0);
            }
            session.CompletePending(true);

            // Evict all records from main memory of hybrid log
            fht.Log.FlushAndEvict(true);

            // Read 2000 keys - all should be served from disk, populating and evicting the read cache FIFO
            for (int i = 0; i < 2000; i++)
            {
                OutputStruct output = default;
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
                Assert.IsTrue(status.IsPending);
                session.CompletePending(true);
            }

            // Read last 100 keys - all should be served from cache
            for (int i = 1900; i < 2000; i++)
            {
                OutputStruct output = default;
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
                Assert.IsTrue(status.Found);
                Assert.AreEqual(value.vfield1, output.value.vfield1);
                Assert.AreEqual(value.vfield2, output.value.vfield2);
            }

            // Evict the read cache entirely
            fht.ReadCache.FlushAndEvict(true);

            // Read 100 keys - all should be served from disk, populating cache
            for (int i = 1900; i < 2000; i++)
            {
                OutputStruct output = default;
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
                Assert.IsTrue(status.IsPending);
                session.CompletePending(true);
            }

            // Read 100 keys - all should be served from cache
            for (int i = 1900; i < 2000; i++)
            {
                OutputStruct output = default;
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
                Assert.IsTrue(status.Found);
                Assert.AreEqual(value.vfield1, output.value.vfield1);
                Assert.AreEqual(value.vfield2, output.value.vfield2);
            }

            // Upsert to overwrite the read cache
            for (int i = 1900; i < 1950; i++)
            {
                var key1 = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i + 1, vfield2 = i + 2
                };
                session.Upsert(ref key1, ref value, Empty.Default, 0);
            }

            // RMW to overwrite the read cache
            for (int i = 1950; i < 2000; i++)
            {
                OutputStruct output = default;
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                input = new InputStruct {
                    ifield1 = 1, ifield2 = 1
                };
                var status = session.RMW(ref key1, ref input, ref output, Empty.Default, 0);
                if (status.IsPending)
                {
                    session.CompletePending(true);
                }
                else
                {
                    Assert.AreEqual(i + 1, output.value.vfield1);
                    Assert.AreEqual(i + 2, output.value.vfield2);
                }
            }

            // Read 100 keys
            for (int i = 1900; i < 2000; i++)
            {
                OutputStruct output = default;
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i + 1, vfield2 = i + 2
                };

                var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
                Assert.IsTrue(status.Found);
                Assert.AreEqual(value.vfield1, output.value.vfield1);
                Assert.AreEqual(value.vfield2, output.value.vfield2);
            }
        }
Esempio n. 22
0
        public void NativeDiskWriteReadCache2()
        {
            using var session = fht.NewSession(new Functions());

            InputStruct input = default;

            for (int i = 0; i < 2000; i++)
            {
                var key1 = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };
                session.Upsert(ref key1, ref value, Empty.Default, 0);
            }
            session.CompletePending(true);

            // Dispose the hybrid log from memory entirely
            fht.Log.DisposeFromMemory();

            // Read 2000 keys - all should be served from disk, populating and evicting the read cache FIFO
            for (int i = 0; i < 2000; i++)
            {
                OutputStruct output = default;
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
                Assert.IsTrue(status.IsPending);
                session.CompletePending(true);
            }

            // Read last 100 keys - all should be served from cache
            for (int i = 1900; i < 2000; i++)
            {
                OutputStruct output = default;
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
                Assert.IsTrue(status.Found);
                Assert.AreEqual(value.vfield1, output.value.vfield1);
                Assert.AreEqual(value.vfield2, output.value.vfield2);
            }

            // Evict the read cache entirely
            fht.ReadCache.FlushAndEvict(true);

            // Read 100 keys - all should be served from disk, populating cache
            for (int i = 1900; i < 2000; i++)
            {
                OutputStruct output = default;
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
                Assert.IsTrue(status.IsPending);
                session.CompletePending(true);
            }

            // Read 100 keys - all should be served from cache
            for (int i = 1900; i < 2000; i++)
            {
                OutputStruct output = default;
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
                Assert.IsTrue(status.Found);
                Assert.AreEqual(value.vfield1, output.value.vfield1);
                Assert.AreEqual(value.vfield2, output.value.vfield2);
            }
        }
Esempio n. 23
0
        public unsafe void NativeInMemWriteRead2()
        {
            // Just use this one instead of all four devices since InMemWriteRead covers all four devices
            deviceType = TestUtils.DeviceType.MLSD;

            int count = 200;

            // Setup(128, new LogSettings { MemorySizeBits = 22, SegmentSizeBits = 22, PageSizeBits = 10 }, deviceType);
            Setup(128, new LogSettings {
                MemorySizeBits = 29
            }, deviceType);
            uContext.ResumeThread();

            try
            {
                InputStruct input = default;

                Random r = new(10);
                for (int c = 0; c < count; c++)
                {
                    var i    = r.Next(10000);
                    var key1 = new KeyStruct {
                        kfield1 = i, kfield2 = i + 1
                    };
                    var value = new ValueStruct {
                        vfield1 = i, vfield2 = i + 1
                    };
                    uContext.Upsert(ref key1, ref value, Empty.Default, 0);
                }

                r = new Random(10);

                for (int c = 0; c < count; c++)
                {
                    var          i      = r.Next(10000);
                    OutputStruct output = default;
                    var          key1   = new KeyStruct {
                        kfield1 = i, kfield2 = i + 1
                    };
                    var value = new ValueStruct {
                        vfield1 = i, vfield2 = i + 1
                    };

                    if (uContext.Read(ref key1, ref input, ref output, Empty.Default, 0).IsPending)
                    {
                        uContext.CompletePending(true);
                    }

                    Assert.AreEqual(value.vfield1, output.value.vfield1);
                    Assert.AreEqual(value.vfield2, output.value.vfield2);
                }

                // Clean up and retry - should not find now
                fht.Log.ShiftBeginAddress(fht.Log.TailAddress, truncateLog: true);

                r = new Random(10);
                for (int c = 0; c < count; c++)
                {
                    var          i      = r.Next(10000);
                    OutputStruct output = default;
                    var          key1   = new KeyStruct {
                        kfield1 = i, kfield2 = i + 1
                    };
                    Assert.IsFalse(uContext.Read(ref key1, ref input, ref output, Empty.Default, 0).Found);
                }
            }
            finally
            {
                uContext.SuspendThread();
            }
        }
Esempio n. 24
0
        public unsafe void TestShiftHeadAddress([Values] TestUtils.DeviceType deviceType)
        {
            InputStruct input     = default;
            const int   RandSeed  = 10;
            const int   RandRange = 10000;
            const int   NumRecs   = 200;

            Random r  = new(RandSeed);
            var    sw = Stopwatch.StartNew();

            Setup(128, new LogSettings {
                MemorySizeBits = 22, SegmentSizeBits = 22, PageSizeBits = 10
            }, deviceType);
            uContext.ResumeThread();

            try
            {
                for (int c = 0; c < NumRecs; c++)
                {
                    var i    = r.Next(RandRange);
                    var key1 = new KeyStruct {
                        kfield1 = i, kfield2 = i + 1
                    };
                    var value = new ValueStruct {
                        vfield1 = i, vfield2 = i + 1
                    };
                    uContext.Upsert(ref key1, ref value, Empty.Default, 0);
                }

                r = new Random(RandSeed);
                sw.Restart();

                for (int c = 0; c < NumRecs; c++)
                {
                    var          i      = r.Next(RandRange);
                    OutputStruct output = default;
                    var          key1   = new KeyStruct {
                        kfield1 = i, kfield2 = i + 1
                    };
                    var value = new ValueStruct {
                        vfield1 = i, vfield2 = i + 1
                    };

                    if (!uContext.Read(ref key1, ref input, ref output, Empty.Default, 0).IsPending)
                    {
                        Assert.AreEqual(value.vfield1, output.value.vfield1);
                        Assert.AreEqual(value.vfield2, output.value.vfield2);
                    }
                }
                uContext.CompletePending(true);

                // Shift head and retry - should not find in main memory now
                fht.Log.FlushAndEvict(true);

                r = new Random(RandSeed);
                sw.Restart();

                for (int c = 0; c < NumRecs; c++)
                {
                    var          i      = r.Next(RandRange);
                    OutputStruct output = default;
                    var          key1   = new KeyStruct {
                        kfield1 = i, kfield2 = i + 1
                    };
                    Status foundStatus = uContext.Read(ref key1, ref input, ref output, Empty.Default, 0);
                    Assert.IsTrue(foundStatus.IsPending);
                }

                uContext.CompletePendingWithOutputs(out var outputs, wait: true);
                int count = 0;
                while (outputs.Next())
                {
                    count++;
                    Assert.AreEqual(outputs.Current.Key.kfield1, outputs.Current.Output.value.vfield1);
                    Assert.AreEqual(outputs.Current.Key.kfield2, outputs.Current.Output.value.vfield2);
                }
                outputs.Dispose();
                Assert.AreEqual(NumRecs, count);
            }
            finally
            {
                uContext.SuspendThread();
            }
        }
Esempio n. 25
0
        public unsafe void NativeInMemRMWNoRefKeys([Values] TestUtils.DeviceType deviceType)
        {
            InputStruct input = default;

            Setup(128, new LogSettings {
                MemorySizeBits = 22, SegmentSizeBits = 22, PageSizeBits = 10
            }, deviceType);
            uContext.ResumeThread();

            try
            {
                var nums = Enumerable.Range(0, 1000).ToArray();
                var rnd  = new Random(11);
                for (int i = 0; i < nums.Length; ++i)
                {
                    int randomIndex = rnd.Next(nums.Length);
                    int temp        = nums[randomIndex];
                    nums[randomIndex] = nums[i];
                    nums[i]           = temp;
                }

                for (int j = 0; j < nums.Length; ++j)
                {
                    var i    = nums[j];
                    var key1 = new KeyStruct {
                        kfield1 = i, kfield2 = i + 1
                    };
                    input = new InputStruct {
                        ifield1 = i, ifield2 = i + 1
                    };
                    uContext.RMW(ref key1, ref input, Empty.Default, 0);
                }
                for (int j = 0; j < nums.Length; ++j)
                {
                    var i    = nums[j];
                    var key1 = new KeyStruct {
                        kfield1 = i, kfield2 = i + 1
                    };
                    input = new InputStruct {
                        ifield1 = i, ifield2 = i + 1
                    };
                    uContext.RMW(key1, input);  // no ref and do not set any other params
                }

                OutputStruct output = default;
                Status       status;
                KeyStruct    key;

                for (int j = 0; j < nums.Length; ++j)
                {
                    var i = nums[j];

                    key = new KeyStruct {
                        kfield1 = i, kfield2 = i + 1
                    };
                    ValueStruct value = new() { vfield1 = i, vfield2 = i + 1 };

                    status = uContext.Read(ref key, ref input, ref output, Empty.Default, 0);

                    AssertCompleted(new(StatusCode.Found), status);
                    Assert.AreEqual(2 * value.vfield1, output.value.vfield1);
                    Assert.AreEqual(2 * value.vfield2, output.value.vfield2);
                }

                key = new KeyStruct {
                    kfield1 = nums.Length, kfield2 = nums.Length + 1
                };
                status = uContext.Read(ref key, ref input, ref output, Empty.Default, 0);
                AssertCompleted(new(StatusCode.NotFound), status);
            }
            finally
            {
                uContext.SuspendThread();
            }
        }
Esempio n. 26
0
        public void SessionTest5()
        {
            var session = fht.NewSession(new Functions());

            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 16, kfield2 = 17
            };
            var value1 = new ValueStruct {
                vfield1 = 26, vfield2 = 27
            };

            session.Upsert(ref key1, ref value1, Empty.Default, 0);
            var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);

            if (status == Status.PENDING)
            {
                session.CompletePending(true);
            }
            else
            {
                Assert.IsTrue(status == Status.OK);
            }

            Assert.IsTrue(output.value.vfield1 == value1.vfield1);
            Assert.IsTrue(output.value.vfield2 == value1.vfield2);

            session.Dispose();

            session = fht.NewSession(new Functions());

            var key2 = new KeyStruct {
                kfield1 = 17, kfield2 = 18
            };
            var value2 = new ValueStruct {
                vfield1 = 27, vfield2 = 28
            };

            session.Upsert(ref key2, ref value2, Empty.Default, 0);

            status = session.Read(ref key2, ref input, ref output, Empty.Default, 0);

            if (status == Status.PENDING)
            {
                session.CompletePending(true);
            }
            else
            {
                Assert.IsTrue(status == Status.OK);
            }

            status = session.Read(ref key2, ref input, ref output, Empty.Default, 0);

            if (status == Status.PENDING)
            {
                session.CompletePending(true);
            }
            else
            {
                Assert.IsTrue(status == Status.OK);
            }

            Assert.IsTrue(output.value.vfield1 == value2.vfield1);
            Assert.IsTrue(output.value.vfield2 == value2.vfield2);

            session.Dispose();
        }
Esempio n. 27
0
 public OutputGroup()
 {
     billboard = new OutputStruct();
     tri       = new OutputStruct();
 }
Esempio n. 28
0
        public void SessionTest5()
        {
            var session = fht.NewSession(new Functions());

            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 16, kfield2 = 17
            };
            var value1 = new ValueStruct {
                vfield1 = 26, vfield2 = 27
            };

            session.Upsert(ref key1, ref value1, Empty.Default, 0);
            var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);

            if (status.IsPending)
            {
                session.CompletePendingWithOutputs(out var outputs, wait: true);
                (status, output) = GetSinglePendingResult(outputs);
            }

            Assert.IsTrue(status.Found);
            Assert.AreEqual(value1.vfield1, output.value.vfield1);
            Assert.AreEqual(value1.vfield2, output.value.vfield2);

            session.Dispose();

            session = fht.NewSession(new Functions());

            var key2 = new KeyStruct {
                kfield1 = 17, kfield2 = 18
            };
            var value2 = new ValueStruct {
                vfield1 = 27, vfield2 = 28
            };

            session.Upsert(ref key2, ref value2, Empty.Default, 0);

            status = session.Read(ref key2, ref input, ref output, Empty.Default, 0);

            if (status.IsPending)
            {
                session.CompletePendingWithOutputs(out var outputs, wait: true);
                (status, output) = GetSinglePendingResult(outputs);
            }
            Assert.IsTrue(status.Found);

            status = session.Read(ref key2, ref input, ref output, Empty.Default, 0);

            if (status.IsPending)
            {
                session.CompletePendingWithOutputs(out var outputs, wait: true);
                (status, output) = GetSinglePendingResult(outputs);
            }

            Assert.IsTrue(status.Found);
            Assert.AreEqual(value2.vfield1, output.value.vfield1);
            Assert.AreEqual(value2.vfield2, output.value.vfield2);

            session.Dispose();
        }