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