Constant project_init::includes::RECO_TEST_COMMAND [] [src]

pub const RECO_TEST_COMMAND: &'static str = "package main\n\nimport (\n\t\"encoding/binary\"\n\t\"fmt\"\n\t\"os\"\n\t\"xcl\"\n)\n\nfunc main() {\n\t// Allocate a world for interacting with kernels\n\tworld := xcl.NewWorld()\n\tdefer world.Release()\n\n\t// Import the kernel.\n\t// Right now these two idenitifers are hard coded as an output from the build process\n\tkrnl := world.Import(\"kernel_test\").GetKernel(\"reconfigure_io_sdaccel_builder_stub_0_1\")\n\tdefer krnl.Release()\n\n\t// Allocate a buffer on the FPGA to store the return value of our computation\n\t// The output is a uint32, so we use 4 bytes to store it\n\tbuff := world.Malloc(xcl.WriteOnly, 4)\n\tdefer buff.Free()\n\n\t// Pass the arguments to the kernel\n\n\t// Set the first operand to 1\n\tkrnl.SetArg(0, 1)\n\t// Set the second operand to 2\n\tkrnl.SetArg(1, 2)\n\t// Set the pointer to the output buffer\n\tkrnl.SetMemoryArg(2, buff)\n\n\t// Run the kernel with the supplied arguments\n\tkrnl.Run(1, 1, 1)\n\n\t// Decode the byte slice given by the FPGA into the uint32 we\'re expecting\n\tvar ret uint32\n\terr := binary.Read(buff.Reader(), binary.LittleEndian, &ret)\n\tif err != nil {\n\t\tfmt.Println(\"binary.Read failed:\", err)\n\t}\n\n\t// Print the value given by the FPGA\n\tfmt.Printf(\"%d\\n\", ret)\n\n\t// Exit with an error if the value is not correct\n\tif ret != 3 {\n\t\tos.Exit(1)\n\t}\n}\n"