github.com/goshafaq/sonic@v0.0.0-20231026082336-871835fb94c6/internal/native/avx2/recover_amd64_test.go (about) 1 // Code generated by Makefile, DO NOT EDIT. 2 3 /** 4 * Copyright 2023 ByteDance Inc. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package avx2 20 21 import ( 22 "os" 23 "runtime" 24 "runtime/debug" 25 "testing" 26 "time" 27 "unsafe" 28 29 "github.com/goshafaq/sonic/internal/native/types" 30 "github.com/goshafaq/sonic/loader" 31 ) 32 33 var ( 34 debugAsyncGC = os.Getenv("SONIC_NO_ASYNC_GC") == "" 35 ) 36 37 var stubs = []loader.GoC{ 38 {"_f32toa", nil, &__f32toa}, 39 {"_f64toa", nil, &__f64toa}, 40 {"_fsm_exec", nil, &__fsm_exec}, 41 {"_get_by_path", nil, &__get_by_path}, 42 {"_html_escape", nil, &__html_escape}, 43 {"_i64toa", nil, &__i64toa}, 44 {"_lspace", nil, &__lspace}, 45 {"_quote", nil, &__quote}, 46 {"_skip_array", nil, &__skip_array}, 47 {"_skip_number", nil, &__skip_number}, 48 {"_skip_object", nil, &__skip_object}, 49 {"_skip_one", nil, &__skip_one}, 50 {"_skip_one_fast", nil, &__skip_one_fast}, 51 {"_u64toa", nil, &__u64toa}, 52 {"_unquote", nil, &__unquote}, 53 {"_validate_one", nil, &__validate_one}, 54 {"_validate_utf8", nil, &__validate_utf8}, 55 {"_validate_utf8_fast", nil, &__validate_utf8_fast}, 56 {"_value", nil, &__value}, 57 {"_vnumber", nil, &__vnumber}, 58 {"_vsigned", nil, &__vsigned}, 59 {"_vstring", nil, &__vstring}, 60 {"_vunsigned", nil, &__vunsigned}, 61 } 62 63 func TestMain(m *testing.M) { 64 loader.WrapGoC(Text__native_entry__, Funcs, stubs, "avx2", "avx2/native.c") 65 66 go func() { 67 if !debugAsyncGC { 68 return 69 } 70 println("Begin GC looping...") 71 for { 72 runtime.GC() 73 debug.FreeOSMemory() 74 } 75 println("stop GC looping!") 76 }() 77 time.Sleep(time.Millisecond * 100) 78 m.Run() 79 } 80 81 func TestRecover_f64toa(t *testing.T) { 82 defer func() { 83 if r := recover(); r != nil { 84 t.Log("recover: ", r) 85 } else { 86 t.Fatal("no panic") 87 } 88 }() 89 _ = f64toa(nil, 123) 90 } 91 92 func TestRecover_f32toa(t *testing.T) { 93 defer func() { 94 if r := recover(); r != nil { 95 t.Log("recover: ", r) 96 } else { 97 t.Fatal("no panic") 98 } 99 }() 100 _ = f32toa(nil, 123) 101 } 102 103 func TestRecover_i64toa(t *testing.T) { 104 defer func() { 105 if r := recover(); r != nil { 106 t.Log("recover: ", r) 107 } else { 108 t.Fatal("no panic") 109 } 110 }() 111 _ = i64toa(nil, 123) 112 } 113 114 func TestRecover_u64toa(t *testing.T) { 115 defer func() { 116 if r := recover(); r != nil { 117 t.Log("recover: ", r) 118 } else { 119 t.Fatal("no panic") 120 } 121 }() 122 _ = u64toa(nil, 123) 123 } 124 125 func TestRecover_lspace(t *testing.T) { 126 defer func() { 127 if r := recover(); r != nil { 128 t.Log("recover: ", r) 129 } else { 130 t.Fatal("no panic") 131 } 132 }() 133 _ = lspace(nil, 2, 0) 134 } 135 136 func TestRecover_quote(t *testing.T) { 137 var dn = 10 138 var dp = make([]byte, dn) 139 var sp = []byte("123") 140 t.Run("sp", func(t *testing.T) { 141 defer func() { 142 if r := recover(); r != nil { 143 t.Log("recover: ", r) 144 } else { 145 t.Fatal("no panic") 146 } 147 }() 148 _ = quote(nil, 3, unsafe.Pointer(&dp[0]), &dn, 0) 149 }) 150 t.Run("dp", func(t *testing.T) { 151 defer func() { 152 if r := recover(); r != nil { 153 t.Log("recover: ", r) 154 } else { 155 t.Fatal("no panic") 156 } 157 }() 158 _ = quote(unsafe.Pointer(&sp[0]), 3, nil, &dn, 0) 159 }) 160 t.Run("dn", func(t *testing.T) { 161 defer func() { 162 if r := recover(); r != nil { 163 t.Log("recover: ", r) 164 } else { 165 t.Fatal("no panic") 166 } 167 }() 168 _ = quote(unsafe.Pointer(&sp[0]), 3, unsafe.Pointer(&dp[0]), nil, 0) 169 }) 170 } 171 172 func TestRecover_html_escape(t *testing.T) { 173 var dn = 10 174 var dp = make([]byte, dn) 175 var sp = []byte("123") 176 t.Run("sp", func(t *testing.T) { 177 defer func() { 178 if r := recover(); r != nil { 179 t.Log("recover: ", r) 180 } else { 181 t.Fatal("no panic") 182 } 183 }() 184 _ = html_escape(nil, 3, unsafe.Pointer(&dp[0]), &dn) 185 }) 186 t.Run("dp", func(t *testing.T) { 187 defer func() { 188 if r := recover(); r != nil { 189 t.Log("recover: ", r) 190 } else { 191 t.Fatal("no panic") 192 } 193 }() 194 _ = html_escape(unsafe.Pointer(&sp[0]), 3, nil, &dn) 195 }) 196 t.Run("dn", func(t *testing.T) { 197 defer func() { 198 if r := recover(); r != nil { 199 t.Log("recover: ", r) 200 } else { 201 t.Fatal("no panic") 202 } 203 }() 204 _ = html_escape(unsafe.Pointer(&sp[0]), 3, unsafe.Pointer(&dp[0]), nil) 205 }) 206 } 207 208 func TestRecover_unquote(t *testing.T) { 209 var ep = 0 210 var dp = make([]byte, 10) 211 var sp = []byte("12\\x\"3\"4") 212 t.Run("sp", func(t *testing.T) { 213 defer func() { 214 if r := recover(); r != nil { 215 t.Log("recover: ", r) 216 } else { 217 t.Fatal("no panic") 218 } 219 }() 220 _ = unquote(nil, len(sp), unsafe.Pointer(&dp[0]), &ep, 0) 221 }) 222 t.Run("dp", func(t *testing.T) { 223 defer func() { 224 if r := recover(); r != nil { 225 t.Log("recover: ", r) 226 } else { 227 t.Fatal("no panic") 228 } 229 }() 230 _ = unquote(unsafe.Pointer(&sp[0]), len(sp), nil, &ep, 0) 231 }) 232 t.Run("ep", func(t *testing.T) { 233 defer func() { 234 if r := recover(); r != nil { 235 t.Log("recover: ", r) 236 } else { 237 t.Fatal("no panic") 238 } 239 }() 240 _ = unquote(unsafe.Pointer(&sp[0]), len(sp), unsafe.Pointer(&dp[0]), nil, 0) 241 }) 242 } 243 244 func TestRecover_value(t *testing.T) { 245 var v = new(types.JsonState) 246 var sp = []byte("123") 247 t.Run("sp", func(t *testing.T) { 248 defer func() { 249 if r := recover(); r != nil { 250 t.Log("recover: ", r) 251 } else { 252 t.Fatal("no panic") 253 } 254 }() 255 _ = value(nil, 3, 0, v, 0) 256 }) 257 t.Run("v", func(t *testing.T) { 258 defer func() { 259 if r := recover(); r != nil { 260 t.Log("recover: ", r) 261 } else { 262 t.Fatal("no panic") 263 } 264 }() 265 _ = value(unsafe.Pointer(&sp[0]), 3, 0, nil, 0) 266 }) 267 } 268 269 func TestRecover_vstring(t *testing.T) { 270 var v = new(types.JsonState) 271 var sp = "123" 272 var p = 0 273 t.Run("sp", func(t *testing.T) { 274 defer func() { 275 if r := recover(); r != nil { 276 t.Log("recover: ", r) 277 } else { 278 t.Fatal("no panic") 279 } 280 }() 281 vstring(nil, &p, v, 0) 282 }) 283 t.Run("p", func(t *testing.T) { 284 defer func() { 285 if r := recover(); r != nil { 286 t.Log("recover: ", r) 287 } else { 288 t.Fatal("no panic") 289 } 290 }() 291 vstring(&sp, nil, v, 0) 292 }) 293 t.Run("v", func(t *testing.T) { 294 defer func() { 295 if r := recover(); r != nil { 296 t.Log("recover: ", r) 297 } else { 298 t.Fatal("no panic") 299 } 300 }() 301 vstring(&sp, &p, nil, 0) 302 }) 303 } 304 305 func TestRecover_vnumber(t *testing.T) { 306 var v = new(types.JsonState) 307 var sp = "123" 308 var p = 0 309 t.Run("sp", func(t *testing.T) { 310 defer func() { 311 if r := recover(); r != nil { 312 t.Log("recover: ", r) 313 } else { 314 t.Fatal("no panic") 315 } 316 }() 317 vnumber(nil, &p, v) 318 }) 319 t.Run("p", func(t *testing.T) { 320 defer func() { 321 if r := recover(); r != nil { 322 t.Log("recover: ", r) 323 } else { 324 t.Fatal("no panic") 325 } 326 }() 327 vnumber(&sp, nil, v) 328 }) 329 t.Run("v", func(t *testing.T) { 330 defer func() { 331 if r := recover(); r != nil { 332 t.Log("recover: ", r) 333 } else { 334 t.Fatal("no panic") 335 } 336 }() 337 vnumber(&sp, &p, nil) 338 }) 339 } 340 341 func TestRecover_vsigned(t *testing.T) { 342 var v = new(types.JsonState) 343 var sp = "123" 344 var p = 0 345 t.Run("sp", func(t *testing.T) { 346 defer func() { 347 if r := recover(); r != nil { 348 t.Log("recover: ", r) 349 } else { 350 t.Fatal("no panic") 351 } 352 }() 353 vsigned(nil, &p, v) 354 }) 355 t.Run("p", func(t *testing.T) { 356 defer func() { 357 if r := recover(); r != nil { 358 t.Log("recover: ", r) 359 } else { 360 t.Fatal("no panic") 361 } 362 }() 363 vsigned(&sp, nil, v) 364 }) 365 t.Run("v", func(t *testing.T) { 366 defer func() { 367 if r := recover(); r != nil { 368 t.Log("recover: ", r) 369 } else { 370 t.Fatal("no panic") 371 } 372 }() 373 vsigned(&sp, &p, nil) 374 }) 375 } 376 377 func TestRecover_vunsigned(t *testing.T) { 378 var v = new(types.JsonState) 379 var sp = "123" 380 var p = 0 381 t.Run("sp", func(t *testing.T) { 382 defer func() { 383 if r := recover(); r != nil { 384 t.Log("recover: ", r) 385 } else { 386 t.Fatal("no panic") 387 } 388 }() 389 vunsigned(nil, &p, v) 390 }) 391 t.Run("p", func(t *testing.T) { 392 defer func() { 393 if r := recover(); r != nil { 394 t.Log("recover: ", r) 395 } else { 396 t.Fatal("no panic") 397 } 398 }() 399 vunsigned(&sp, nil, v) 400 }) 401 t.Run("v", func(t *testing.T) { 402 defer func() { 403 if r := recover(); r != nil { 404 t.Log("recover: ", r) 405 } else { 406 t.Fatal("no panic") 407 } 408 }() 409 vunsigned(&sp, &p, nil) 410 }) 411 } 412 413 func TestRecover_skip_one(t *testing.T) { 414 var v = types.NewStateMachine() 415 var sp = "123" 416 var p = 0 417 t.Run("sp", func(t *testing.T) { 418 defer func() { 419 if r := recover(); r != nil { 420 t.Log("recover: ", r) 421 } else { 422 t.Fatal("no panic") 423 } 424 }() 425 _ = skip_one(nil, &p, v, 0) 426 }) 427 t.Run("p", func(t *testing.T) { 428 defer func() { 429 if r := recover(); r != nil { 430 t.Log("recover: ", r) 431 } else { 432 t.Fatal("no panic") 433 } 434 }() 435 _ = skip_one(&sp, nil, v, 0) 436 }) 437 t.Run("v", func(t *testing.T) { 438 defer func() { 439 if r := recover(); r != nil { 440 t.Log("recover: ", r) 441 } else { 442 t.Fatal("no panic") 443 } 444 }() 445 _ = skip_one(&sp, &p, nil, 0) 446 }) 447 } 448 449 func TestRecover_skip_one_fast(t *testing.T) { 450 var sp = "123" 451 var p = 0 452 t.Run("sp", func(t *testing.T) { 453 defer func() { 454 if r := recover(); r != nil { 455 t.Log("recover: ", r) 456 } else { 457 t.Fatal("no panic") 458 } 459 }() 460 _ = skip_one_fast(nil, &p) 461 }) 462 t.Run("p", func(t *testing.T) { 463 defer func() { 464 if r := recover(); r != nil { 465 t.Log("recover: ", r) 466 } else { 467 t.Fatal("no panic") 468 } 469 }() 470 _ = skip_one_fast(&sp, nil) 471 }) 472 } 473 474 func TestRecover_skip_array(t *testing.T) { 475 var v = types.NewStateMachine() 476 var sp = "123" 477 var p = 0 478 t.Run("sp", func(t *testing.T) { 479 defer func() { 480 if r := recover(); r != nil { 481 t.Log("recover: ", r) 482 } else { 483 t.Fatal("no panic") 484 } 485 }() 486 _ = skip_array(nil, &p, v, 0) 487 }) 488 t.Run("p", func(t *testing.T) { 489 defer func() { 490 if r := recover(); r != nil { 491 t.Log("recover: ", r) 492 } else { 493 t.Fatal("no panic") 494 } 495 }() 496 _ = skip_array(&sp, nil, v, 0) 497 }) 498 t.Run("v", func(t *testing.T) { 499 defer func() { 500 if r := recover(); r != nil { 501 t.Log("recover: ", r) 502 } else { 503 t.Fatal("no panic") 504 } 505 }() 506 _ = skip_array(&sp, &p, nil, 0) 507 }) 508 } 509 510 func TestRecover_skip_object(t *testing.T) { 511 var v = types.NewStateMachine() 512 var sp = "123" 513 var p = 0 514 t.Run("sp", func(t *testing.T) { 515 defer func() { 516 if r := recover(); r != nil { 517 t.Log("recover: ", r) 518 } else { 519 t.Fatal("no panic") 520 } 521 }() 522 _ = skip_object(nil, &p, v, 0) 523 }) 524 t.Run("p", func(t *testing.T) { 525 defer func() { 526 if r := recover(); r != nil { 527 t.Log("recover: ", r) 528 } else { 529 t.Fatal("no panic") 530 } 531 }() 532 _ = skip_object(&sp, nil, v, 0) 533 }) 534 t.Run("v", func(t *testing.T) { 535 defer func() { 536 if r := recover(); r != nil { 537 t.Log("recover: ", r) 538 } else { 539 t.Fatal("no panic") 540 } 541 }() 542 _ = skip_object(&sp, &p, nil, 0) 543 }) 544 } 545 546 func TestRecover_skip_number(t *testing.T) { 547 var sp = "123" 548 var p = 0 549 t.Run("sp", func(t *testing.T) { 550 defer func() { 551 if r := recover(); r != nil { 552 t.Log("recover: ", r) 553 } else { 554 t.Fatal("no panic") 555 } 556 }() 557 _ = skip_number(nil, &p) 558 }) 559 t.Run("p", func(t *testing.T) { 560 defer func() { 561 if r := recover(); r != nil { 562 t.Log("recover: ", r) 563 } else { 564 t.Fatal("no panic") 565 } 566 }() 567 _ = skip_number(&sp, nil) 568 }) 569 } 570 571 func TestRecover_get_by_path(t *testing.T) { 572 var v = []interface{}{} 573 var sp = "123" 574 var p = 0 575 var m = types.NewStateMachine() 576 t.Run("sp", func(t *testing.T) { 577 defer func() { 578 if r := recover(); r != nil { 579 t.Log("recover: ", r) 580 } else { 581 t.Fatal("no panic") 582 } 583 }() 584 _ = get_by_path(nil, &p, &v, m) 585 }) 586 t.Run("p", func(t *testing.T) { 587 defer func() { 588 if r := recover(); r != nil { 589 t.Log("recover: ", r) 590 } else { 591 t.Fatal("no panic") 592 } 593 }() 594 _ = get_by_path(&sp, nil, &v, m) 595 }) 596 t.Run("path", func(t *testing.T) { 597 defer func() { 598 if r := recover(); r != nil { 599 t.Log("recover: ", r) 600 } else { 601 t.Fatal("no panic") 602 } 603 }() 604 _ = get_by_path(&sp, &p, nil, m) 605 }) 606 t.Run("m", func(t *testing.T) { 607 defer func() { 608 if r := recover(); r != nil { 609 t.Log("recover: ", r) 610 } else { 611 t.Fatal("no panic") 612 } 613 }() 614 _ = get_by_path(&sp, &p, &v, nil) 615 }) 616 } 617 618 func TestRecover_validate_one(t *testing.T) { 619 var v = types.NewStateMachine() 620 var sp = "123" 621 var p = 0 622 t.Run("sp", func(t *testing.T) { 623 defer func() { 624 if r := recover(); r != nil { 625 t.Log("recover: ", r) 626 } else { 627 t.Fatal("no panic") 628 } 629 }() 630 _ = validate_one(nil, &p, v) 631 }) 632 t.Run("p", func(t *testing.T) { 633 defer func() { 634 if r := recover(); r != nil { 635 t.Log("recover: ", r) 636 } else { 637 t.Fatal("no panic") 638 } 639 }() 640 _ = validate_one(&sp, nil, v) 641 }) 642 t.Run("v", func(t *testing.T) { 643 defer func() { 644 if r := recover(); r != nil { 645 t.Log("recover: ", r) 646 } else { 647 t.Fatal("no panic") 648 } 649 }() 650 _ = validate_one(&sp, &p, nil) 651 }) 652 } 653 654 func TestRecover_validate_utf8(t *testing.T) { 655 var v = types.NewStateMachine() 656 var sp = string([]byte{0xff, 0xff, 0xff}) 657 var p = 0 658 t.Run("sp", func(t *testing.T) { 659 defer func() { 660 if r := recover(); r != nil { 661 t.Log("recover: ", r) 662 } else { 663 t.Fatal("no panic") 664 } 665 }() 666 _ = validate_utf8(nil, &p, v) 667 }) 668 t.Run("p", func(t *testing.T) { 669 defer func() { 670 if r := recover(); r != nil { 671 t.Log("recover: ", r) 672 } else { 673 t.Fatal("no panic") 674 } 675 }() 676 _ = validate_utf8(&sp, nil, v) 677 }) 678 t.Run("v", func(t *testing.T) { 679 defer func() { 680 if r := recover(); r != nil { 681 t.Log("recover: ", r) 682 } else { 683 t.Fatal("no panic") 684 } 685 }() 686 _ = validate_utf8(&sp, &p, nil) 687 }) 688 } 689 690 func TestRecover_validate_utf8_fast(t *testing.T) { 691 defer func() { 692 if r := recover(); r != nil { 693 t.Log("recover: ", r) 694 } else { 695 t.Fatal("no panic") 696 } 697 }() 698 _ = validate_utf8_fast(nil) 699 }