OSDN Git Service

test Add.
[roast/roast_ex.git] / roast_ex / test / js_test / js_test.cpp
diff --git a/roast_ex/test/js_test/js_test.cpp b/roast_ex/test/js_test/js_test.cpp
new file mode 100644 (file)
index 0000000..8395bf2
--- /dev/null
@@ -0,0 +1,122 @@
+#include <stdio.h>
+#include <time.h>
+#include "roast/asm/x86/lexical.hpp"
+#include "roast/stream/memory_stream.hpp"
+
+using namespace ::roast;
+using namespace ::roast::lexical;
+using namespace ::roast::assem::x86::lexical;
+
+#define BUF_SIZE       (1024)
+
+int main()
+{
+       unsigned char actual_buf[BUF_SIZE];
+       unsigned char expect_buf[BUF_SIZE];
+       memset(actual_buf,0,sizeof(actual_buf));
+       memset(expect_buf,0,sizeof(expect_buf));
+
+       //      Read Expect (from NASM Binary)
+       FILE *fp_expect = fopen("mov_test", "rb");
+       if ( fp_expect == NULL ){
+               printf("mov_test Open Error!\n");
+               return 1;
+       }
+       size_t expect_length = fread(expect_buf, 1, sizeof(expect_buf), fp_expect);
+       fclose(fp_expect);
+
+       /////////////////////////////////////////////////////////////////////////
+
+       stream::memory_stream actual_strm(actual_buf,sizeof(actual_buf));
+
+       typedef seq<
+               seq<
+                       //      8bit Register to Register
+                       mov<al, bl>,
+                       mov<cl, dl>,
+                       mov<ah, bh>,
+                       mov<ch, dh>,
+
+                       //      16bit Register to Register
+                       mov<ax, bx>,
+                       mov<ax, cx>,
+                       mov<ax, dx>,
+                       mov<bx, ax>,
+                       mov<dx, ax>,
+                       mov<cx, ax>,
+
+                       _true_analyze
+
+               >,
+               //      8/16bit Immediate to Register
+               mov<al, imm8<0x12> >,
+               mov<ah, imm8<0x34> >,
+               mov<ax, imm16<0x1234> >,
+               mov<bx, imm16<0x5678> >,
+
+               //      8/16bit Immediate to Memory
+               mov<byte_ptr16<0x1234>, imm8<0x12> >,
+               mov<word_ptr16<0x1234>, imm16<0x1234> >,
+
+               //      8/16bit Memory to Register
+               mov<bl, byte_ptr16<0x1234> >,
+               mov<al, byte_ptr16<0x5678> >,
+               mov<bx, word_ptr16<0x1234> >,
+               mov<ax, word_ptr16<0x5678> >,
+
+               //      8/16bit Register to Memory
+               mov<byte_ptr16<0x1234>, bl>,
+               mov<byte_ptr16<0x5678>, al>,
+               mov<word_ptr16<0x1234>, bx>,
+               mov<word_ptr16<0x5678>, ax>,
+
+               //      Segument Register
+               mov<es, ax>,
+               mov<es, bx>,
+               mov<cs, ax>,
+               mov<ds, bx>,
+               mov<ax, es>,
+               mov<bx, es>,
+               mov<ax, cs>,
+               mov<bx, ds>,
+
+               _true_analyze
+
+       > actual_t;
+
+       actual_t o;
+       //o.generate(actual_strm, sized_ptr((void*)boot_img,size) );
+       o.generate(actual_strm, actual_strm );
+
+       /////////////////////////////////////////////////////////////////////////
+
+       size_t comp_length = sizeof(actual_buf) - actual_strm.restsize();
+       if ( expect_length > comp_length )
+               comp_length = expect_length;
+
+       for(size_t i=0; i<comp_length; i++)
+       {
+               printf("expect: %02X, actual: %02X ... ", expect_buf[i], actual_buf[i] );
+               if ( expect_buf[i] == actual_buf[i] )
+                       printf("OK.\n");
+               else
+               {
+                       printf("NG!!\n");
+                       printf("%d(0x%X) byte is not Match, compair was not completely...\n", i, i);
+                       return 2;
+               }
+       }
+       printf("%d byte Completely Match!!\n", comp_length);
+       /*
+       //      Compair
+       if ( memcmp(actual_buf, expect_buf, sizeof(expect_buf)) == 0 )
+       {
+               printf("Completely Match!!\n");
+               return 2;
+       }
+       else
+               printf("Not Match...\n");
+       */
+
+       return 0;
+}