wa-lang.org/wazero@v1.0.2/internal/integration_test/spectest/v1/testdata/data.wast (about)

     1  ;; Test the data section
     2  
     3  ;; Syntax
     4  
     5  (module
     6    (memory $m 1)
     7    (data (i32.const 0))
     8    (data (i32.const 1) "a" "" "bcd")
     9    (data (offset (i32.const 0)))
    10    (data (offset (i32.const 0)) "" "a" "bc" "")
    11    (data 0 (i32.const 0))
    12    (data 0x0 (i32.const 1) "a" "" "bcd")
    13    (data 0x000 (offset (i32.const 0)))
    14    (data 0 (offset (i32.const 0)) "" "a" "bc" "")
    15    (data $m (i32.const 0))
    16    (data $m (i32.const 1) "a" "" "bcd")
    17    (data $m (offset (i32.const 0)))
    18    (data $m (offset (i32.const 0)) "" "a" "bc" "")
    19  )
    20  
    21  ;; Basic use
    22  
    23  (module
    24    (memory 1)
    25    (data (i32.const 0) "a")
    26  )
    27  (module
    28    (import "spectest" "memory" (memory 1))
    29    (data (i32.const 0) "a")
    30  )
    31  
    32  (module
    33    (memory 1)
    34    (data (i32.const 0) "a")
    35    (data (i32.const 3) "b")
    36    (data (i32.const 100) "cde")
    37    (data (i32.const 5) "x")
    38    (data (i32.const 3) "c")
    39  )
    40  (module
    41    (import "spectest" "memory" (memory 1))
    42    (data (i32.const 0) "a")
    43    (data (i32.const 1) "b")
    44    (data (i32.const 2) "cde")
    45    (data (i32.const 3) "f")
    46    (data (i32.const 2) "g")
    47    (data (i32.const 1) "h")
    48  )
    49  
    50  (module
    51    (global (import "spectest" "global_i32") i32)
    52    (memory 1)
    53    (data (global.get 0) "a")
    54  )
    55  (module
    56    (global (import "spectest" "global_i32") i32)
    57    (import "spectest" "memory" (memory 1))
    58    (data (global.get 0) "a")
    59  )
    60  
    61  (module
    62    (global $g (import "spectest" "global_i32") i32)
    63    (memory 1)
    64    (data (global.get $g) "a")
    65  )
    66  (module
    67    (global $g (import "spectest" "global_i32") i32)
    68    (import "spectest" "memory" (memory 1))
    69    (data (global.get $g) "a")
    70  )
    71  
    72  ;; Use of internal globals in constant expressions is not allowed in MVP.
    73  ;; (module (memory 1) (data (global.get 0) "a") (global i32 (i32.const 0)))
    74  ;; (module (memory 1) (data (global.get $g) "a") (global $g i32 (i32.const 0)))
    75  
    76  ;; Corner cases
    77  
    78  (module
    79    (memory 1)
    80    (data (i32.const 0) "a")
    81    (data (i32.const 0xffff) "b")
    82  )
    83  (module
    84    (import "spectest" "memory" (memory 1))
    85    (data (i32.const 0) "a")
    86    (data (i32.const 0xffff) "b")
    87  )
    88  
    89  (module
    90    (memory 2)
    91    (data (i32.const 0x1_ffff) "a")
    92  )
    93  
    94  (module
    95    (memory 0)
    96    (data (i32.const 0))
    97  )
    98  (module
    99    (import "spectest" "memory" (memory 0))
   100    (data (i32.const 0))
   101  )
   102  
   103  (module
   104    (memory 0 0)
   105    (data (i32.const 0))
   106  )
   107  
   108  (module
   109    (memory 1)
   110    (data (i32.const 0x1_0000) "")
   111  )
   112  
   113  (module
   114    (memory 0)
   115    (data (i32.const 0) "" "")
   116  )
   117  (module
   118    (import "spectest" "memory" (memory 0))
   119    (data (i32.const 0) "" "")
   120  )
   121  
   122  (module
   123    (memory 0 0)
   124    (data (i32.const 0) "" "")
   125  )
   126  
   127  (module
   128    (import "spectest" "memory" (memory 0))
   129    (data (i32.const 0) "a")
   130  )
   131  
   132  (module
   133    (import "spectest" "memory" (memory 0 3))
   134    (data (i32.const 0) "a")
   135  )
   136  
   137  (module
   138    (global (import "spectest" "global_i32") i32)
   139    (import "spectest" "memory" (memory 0))
   140    (data (global.get 0) "a")
   141  )
   142  
   143  (module
   144    (global (import "spectest" "global_i32") i32)
   145    (import "spectest" "memory" (memory 0 3))
   146    (data (global.get 0) "a")
   147  )
   148  
   149  (module
   150    (import "spectest" "memory" (memory 0))
   151    (data (i32.const 1) "a")
   152  )
   153  
   154  (module
   155    (import "spectest" "memory" (memory 0 3))
   156    (data (i32.const 1) "a")
   157  )
   158  
   159  ;; Invalid bounds for data
   160  
   161  (assert_unlinkable
   162    (module
   163      (memory 0)
   164      (data (i32.const 0) "a")
   165    )
   166    "data segment does not fit"
   167  )
   168  
   169  (assert_unlinkable
   170    (module
   171      (memory 0 0)
   172      (data (i32.const 0) "a")
   173    )
   174    "data segment does not fit"
   175  )
   176  
   177  (assert_unlinkable
   178    (module
   179      (memory 0 1)
   180      (data (i32.const 0) "a")
   181    )
   182    "data segment does not fit"
   183  )
   184  
   185  (assert_unlinkable
   186    (module
   187      (memory 0)
   188      (data (i32.const 1))
   189    )
   190    "data segment does not fit"
   191  )
   192  
   193  (assert_unlinkable
   194    (module
   195      (memory 0 1)
   196      (data (i32.const 1))
   197    )
   198    "data segment does not fit"
   199  )
   200  
   201  ;; This seems to cause a time-out on Travis.
   202  (;assert_unlinkable
   203    (module
   204      (memory 0x10000)
   205      (data (i32.const 0xffffffff) "ab")
   206    )
   207    ""  ;; either out of memory or segment does not fit
   208  ;)
   209  
   210  (assert_unlinkable
   211    (module
   212      (global (import "spectest" "global_i32") i32)
   213      (memory 0)
   214      (data (global.get 0) "a")
   215    )
   216    "data segment does not fit"
   217  )
   218  
   219  (assert_unlinkable
   220    (module
   221      (memory 1 2)
   222      (data (i32.const 0x1_0000) "a")
   223    )
   224    "data segment does not fit"
   225  )
   226  (assert_unlinkable
   227    (module
   228      (import "spectest" "memory" (memory 1))
   229      (data (i32.const 0x1_0000) "a")
   230    )
   231    "data segment does not fit"
   232  )
   233  
   234  (assert_unlinkable
   235    (module
   236      (memory 2)
   237      (data (i32.const 0x2_0000) "a")
   238    )
   239    "data segment does not fit"
   240  )
   241  
   242  (assert_unlinkable
   243    (module
   244      (memory 2 3)
   245      (data (i32.const 0x2_0000) "a")
   246    )
   247    "data segment does not fit"
   248  )
   249  
   250  (assert_unlinkable
   251    (module
   252      (memory 1)
   253      (data (i32.const -1) "a")
   254    )
   255    "data segment does not fit"
   256  )
   257  (assert_unlinkable
   258    (module
   259      (import "spectest" "memory" (memory 1))
   260      (data (i32.const -1) "a")
   261    )
   262    "data segment does not fit"
   263  )
   264  
   265  (assert_unlinkable
   266    (module
   267      (memory 2)
   268      (data (i32.const -100) "a")
   269    )
   270    "data segment does not fit"
   271  )
   272  (assert_unlinkable
   273    (module
   274      (import "spectest" "memory" (memory 1))
   275      (data (i32.const -100) "a")
   276    )
   277    "data segment does not fit"
   278  )
   279  
   280  ;; Data without memory
   281  
   282  (assert_invalid
   283    (module
   284      (data (i32.const 0) "")
   285    )
   286    "unknown memory 0"
   287  )
   288  
   289  ;; Invalid offsets
   290  
   291  (assert_invalid
   292    (module
   293      (memory 1)
   294      (data (i64.const 0))
   295    )
   296    "type mismatch"
   297  )
   298  
   299  (assert_invalid
   300    (module
   301      (memory 1)
   302      (data (i32.ctz (i32.const 0)))
   303    )
   304    "constant expression required"
   305  )
   306  
   307  (assert_invalid
   308    (module
   309      (memory 1)
   310      (data (nop))
   311    )
   312    "constant expression required"
   313  )
   314  
   315  (assert_invalid
   316    (module
   317      (memory 1)
   318      (data (offset (nop) (i32.const 0)))
   319    )
   320    "constant expression required"
   321  )
   322  
   323  (assert_invalid
   324    (module
   325      (memory 1)
   326      (data (offset (i32.const 0) (nop)))
   327    )
   328    "constant expression required"
   329  )
   330  
   331  ;; Use of internal globals in constant expressions is not allowed in MVP.
   332  ;; (assert_invalid
   333  ;;   (module (memory 1) (data (global.get $g)) (global $g (mut i32) (i32.const 0)))
   334  ;;   "constant expression required"
   335  ;; )