~neovim-ppa/neovim-ppa/neovim-deps

« back to all changes in this revision

Viewing changes to src/libuv/test/test-fs-event.c

  • Committer: marvim
  • Date: 2020-08-05 13:28:24 UTC
  • Revision ID: git-v1:140b815f249fe8e10c313376bb0e5ee4afdb2699
deps src: Automatic update

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <string.h>
26
26
#include <fcntl.h>
27
27
 
 
28
#if defined(__APPLE__) && !TARGET_OS_IPHONE
 
29
# include <AvailabilityMacros.h>
 
30
#endif
 
31
 
28
32
#ifndef HAVE_KQUEUE
29
33
# if defined(__APPLE__) ||                                                    \
30
34
     defined(__DragonFly__) ||                                                \
47
51
static const int fs_event_file_count = 16;
48
52
#if defined(__APPLE__) || defined(_WIN32)
49
53
static const char file_prefix_in_subdir[] = "subdir";
 
54
static int fs_multievent_cb_called;
50
55
#endif
51
56
static uv_timer_t timer;
52
57
static int timer_cb_called;
280
285
  if (filename && strcmp(filename, file_prefix_in_subdir) == 0)
281
286
    return;
282
287
#endif
283
 
  fs_event_cb_called++;
 
288
  fs_multievent_cb_called++;
284
289
  ASSERT(handle == &fs_event);
285
290
  ASSERT(status == 0);
286
291
  ASSERT(events == UV_CHANGE || events == UV_RENAME);
298
303
  if (fs_event_created + fs_event_removed == fs_event_file_count) {
299
304
    /* Once we've processed all create events, delete all files */
300
305
    ASSERT(0 == uv_timer_start(&timer, fs_event_unlink_files_in_subdir, 1, 0));
301
 
  } else if (fs_event_cb_called == 2 * fs_event_file_count) {
 
306
  } else if (fs_multievent_cb_called == 2 * fs_event_file_count) {
302
307
    /* Once we've processed all create and delete events, stop watching */
303
308
    uv_close((uv_handle_t*) &timer, close_cb);
304
309
    uv_close((uv_handle_t*) handle, close_cb);
393
398
  uv_close((uv_handle_t*) handle, NULL);
394
399
}
395
400
 
 
401
static void fs_event_cb_close(uv_fs_event_t* handle,
 
402
                              const char* filename,
 
403
                              int events,
 
404
                              int status) {
 
405
  ASSERT(status == 0);
 
406
 
 
407
  ASSERT(fs_event_cb_called < 3);
 
408
  ++fs_event_cb_called;
 
409
 
 
410
  if (fs_event_cb_called == 3) {
 
411
    uv_close((uv_handle_t*) handle, close_cb);
 
412
  }
 
413
}
 
414
 
 
415
 
396
416
TEST_IMPL(fs_event_watch_dir) {
397
417
#if defined(NO_FS_EVENTS)
398
418
  RETURN_SKIP(NO_FS_EVENTS);
434
454
  return 0;
435
455
}
436
456
 
 
457
 
437
458
TEST_IMPL(fs_event_watch_dir_recursive) {
438
459
#if defined(__APPLE__) || defined(_WIN32)
439
460
  uv_loop_t* loop;
440
461
  int r;
 
462
  uv_fs_event_t fs_event_root;
441
463
 
442
464
  /* Setup */
443
465
  loop = uv_default_loop();
451
473
 
452
474
  r = uv_fs_event_init(loop, &fs_event);
453
475
  ASSERT(r == 0);
454
 
  r = uv_fs_event_start(&fs_event, fs_event_cb_dir_multi_file_in_subdir, "watch_dir", UV_FS_EVENT_RECURSIVE);
 
476
  r = uv_fs_event_start(&fs_event,
 
477
                        fs_event_cb_dir_multi_file_in_subdir,
 
478
                        "watch_dir",
 
479
                        UV_FS_EVENT_RECURSIVE);
455
480
  ASSERT(r == 0);
456
481
  r = uv_timer_init(loop, &timer);
457
482
  ASSERT(r == 0);
458
483
  r = uv_timer_start(&timer, fs_event_create_files_in_subdir, 100, 0);
459
484
  ASSERT(r == 0);
460
485
 
 
486
#ifndef _WIN32
 
487
  /* Also try to watch the root directory.
 
488
   * This will be noisier, so we're just checking for any couple events to happen. */
 
489
  r = uv_fs_event_init(loop, &fs_event_root);
 
490
  ASSERT(r == 0);
 
491
  r = uv_fs_event_start(&fs_event_root,
 
492
                        fs_event_cb_close,
 
493
                        "/",
 
494
                        UV_FS_EVENT_RECURSIVE);
 
495
  ASSERT(r == 0);
 
496
#else
 
497
  fs_event_cb_called += 3;
 
498
  close_cb_called += 1;
 
499
  (void)fs_event_root;
 
500
#endif
 
501
 
461
502
  uv_run(loop, UV_RUN_DEFAULT);
462
503
 
463
 
  ASSERT(fs_event_cb_called == fs_event_created + fs_event_removed);
464
 
  ASSERT(close_cb_called == 2);
 
504
  ASSERT(fs_multievent_cb_called == fs_event_created + fs_event_removed);
 
505
  ASSERT(fs_event_cb_called == 3);
 
506
  ASSERT(close_cb_called == 3);
465
507
 
466
508
  /* Cleanup */
467
509
  fs_event_unlink_files_in_subdir(NULL);
596
638
   * versions. Give a long delay here to let the system settle before running
597
639
   * the test. */
598
640
  uv_sleep(1100);
 
641
  uv_update_time(loop);
599
642
#endif
600
643
 
601
644
  r = uv_fs_event_init(loop, &fs_event);
656
699
  /* Setup */
657
700
  remove("watch_file");
658
701
  create_file("watch_file");
 
702
#if defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_12)
 
703
  /* Empirically, kevent seems to (sometimes) report the preceeding
 
704
   * create_file events prior to macOS 10.11.6 in the subsequent fs_event_start
 
705
   * So let the system settle before running the test. */
 
706
  uv_sleep(1100);
 
707
  uv_update_time(loop);
 
708
#endif
659
709
 
660
710
  r = uv_fs_event_init(loop, &fs_event);
661
711
  ASSERT(r == 0);
864
914
  return 0;
865
915
}
866
916
 
867
 
static void fs_event_cb_close(uv_fs_event_t* handle, const char* filename,
868
 
    int events, int status) {
869
 
  ASSERT(status == 0);
870
 
 
871
 
  ASSERT(fs_event_cb_called < 3);
872
 
  ++fs_event_cb_called;
873
 
 
874
 
  if (fs_event_cb_called == 3) {
875
 
    uv_close((uv_handle_t*) handle, close_cb);
876
 
  }
877
 
}
878
 
 
879
917
TEST_IMPL(fs_event_close_in_callback) {
880
918
#if defined(NO_FS_EVENTS)
881
919
  RETURN_SKIP(NO_FS_EVENTS);