summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJair Gonzalez <jair.de.jesus.gonzalez.plascencia@linux.intel.com>2017-08-16 15:59:41 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-01-07 12:14:34 +0000
commite95ce3fe3b31e63aedf891bfd9a3397bb5f91ba8 (patch)
tree3c12c6449f458b2812ffaa7f66cbd78bc6ef9d96
parent35226b3307dcc0687c36fea481a6add4944906d4 (diff)
downloadpoky-e95ce3fe3b31e63aedf891bfd9a3397bb5f91ba8.tar.gz
bitbake: tests/event: tests: Add event classes test class
This change adds EventClassesTest class to bb/tests/event.py, including 47 new test cases for the public interfaces of the bitbake event and related helper classes. [YOCTO #10773] (Bitbake rev: ee5fe4431713b8a29bdb424a29460965374b3234) Signed-off-by: Jair Gonzalez <jair.de.jesus.gonzalez.plascencia@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/tests/event.py499
1 files changed, 499 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/event.py b/bitbake/lib/bb/tests/event.py
index 036fd7e18d..d3a5f6269f 100644
--- a/bitbake/lib/bb/tests/event.py
+++ b/bitbake/lib/bb/tests/event.py
@@ -485,3 +485,502 @@ class EventHandlingTest(unittest.TestCase):
485 # processed before finishing handling the first worker event. 485 # processed before finishing handling the first worker event.
486 self.assertEqual(self._threadlock_test_calls, 486 self.assertEqual(self._threadlock_test_calls,
487 ["w1_ui1", "w2_ui1", "w1_ui2", "w2_ui2"]) 487 ["w1_ui1", "w2_ui1", "w1_ui2", "w2_ui2"])
488
489
490class EventClassesTest(unittest.TestCase):
491 """ Event classes test class """
492
493 _worker_pid = 54321
494
495 def setUp(self):
496 bb.event.worker_pid = EventClassesTest._worker_pid
497
498 def test_Event(self):
499 """ Test the Event base class """
500 event = bb.event.Event()
501 self.assertEqual(event.pid, EventClassesTest._worker_pid)
502
503 def test_HeartbeatEvent(self):
504 """ Test the HeartbeatEvent class """
505 time = 10
506 event = bb.event.HeartbeatEvent(time)
507 self.assertEqual(event.time, time)
508 self.assertEqual(event.pid, EventClassesTest._worker_pid)
509
510 def test_OperationStarted(self):
511 """ Test OperationStarted event class """
512 msg = "Foo Bar"
513 event = bb.event.OperationStarted(msg)
514 self.assertEqual(event.msg, msg)
515 self.assertEqual(event.pid, EventClassesTest._worker_pid)
516
517 def test_OperationCompleted(self):
518 """ Test OperationCompleted event class """
519 msg = "Foo Bar"
520 total = 123
521 event = bb.event.OperationCompleted(total, msg)
522 self.assertEqual(event.msg, msg)
523 self.assertEqual(event.total, total)
524 self.assertEqual(event.pid, EventClassesTest._worker_pid)
525
526 def test_OperationProgress(self):
527 """ Test OperationProgress event class """
528 msg = "Foo Bar"
529 total = 123
530 current = 111
531 event = bb.event.OperationProgress(current, total, msg)
532 self.assertEqual(event.msg, msg + ": %s/%s" % (current, total))
533 self.assertEqual(event.pid, EventClassesTest._worker_pid)
534
535 def test_ConfigParsed(self):
536 """ Test the ConfigParsed class """
537 event = bb.event.ConfigParsed()
538 self.assertEqual(event.pid, EventClassesTest._worker_pid)
539
540 def test_MultiConfigParsed(self):
541 """ Test MultiConfigParsed event class """
542 mcdata = {"foobar": "Foo Bar"}
543 event = bb.event.MultiConfigParsed(mcdata)
544 self.assertEqual(event.mcdata, mcdata)
545 self.assertEqual(event.pid, EventClassesTest._worker_pid)
546
547 def test_RecipeEvent(self):
548 """ Test RecipeEvent event base class """
549 callback = lambda a: 2 * a
550 event = bb.event.RecipeEvent(callback)
551 self.assertEqual(event.fn(1), callback(1))
552 self.assertEqual(event.pid, EventClassesTest._worker_pid)
553
554 def test_RecipePreFinalise(self):
555 """ Test RecipePreFinalise event class """
556 callback = lambda a: 2 * a
557 event = bb.event.RecipePreFinalise(callback)
558 self.assertEqual(event.fn(1), callback(1))
559 self.assertEqual(event.pid, EventClassesTest._worker_pid)
560
561 def test_RecipeTaskPreProcess(self):
562 """ Test RecipeTaskPreProcess event class """
563 callback = lambda a: 2 * a
564 tasklist = [("foobar", callback)]
565 event = bb.event.RecipeTaskPreProcess(callback, tasklist)
566 self.assertEqual(event.fn(1), callback(1))
567 self.assertEqual(event.tasklist, tasklist)
568 self.assertEqual(event.pid, EventClassesTest._worker_pid)
569
570 def test_RecipeParsed(self):
571 """ Test RecipeParsed event base class """
572 callback = lambda a: 2 * a
573 event = bb.event.RecipeParsed(callback)
574 self.assertEqual(event.fn(1), callback(1))
575 self.assertEqual(event.pid, EventClassesTest._worker_pid)
576
577 def test_StampUpdate(self):
578 targets = ["foo", "bar"]
579 stampfns = [lambda:"foobar"]
580 event = bb.event.StampUpdate(targets, stampfns)
581 self.assertEqual(event.targets, targets)
582 self.assertEqual(event.stampPrefix, stampfns)
583 self.assertEqual(event.pid, EventClassesTest._worker_pid)
584
585 def test_BuildBase(self):
586 """ Test base class for bitbake build events """
587 name = "foo"
588 pkgs = ["bar"]
589 failures = 123
590 event = bb.event.BuildBase(name, pkgs, failures)
591 self.assertEqual(event.name, name)
592 self.assertEqual(event.pkgs, pkgs)
593 self.assertEqual(event.getFailures(), failures)
594 name = event.name = "bar"
595 pkgs = event.pkgs = ["foo"]
596 self.assertEqual(event.name, name)
597 self.assertEqual(event.pkgs, pkgs)
598 self.assertEqual(event.getFailures(), failures)
599 self.assertEqual(event.pid, EventClassesTest._worker_pid)
600
601 def test_BuildInit(self):
602 """ Test class for bitbake build invocation events """
603 event = bb.event.BuildInit()
604 self.assertEqual(event.name, None)
605 self.assertEqual(event.pkgs, [])
606 self.assertEqual(event.getFailures(), 0)
607 name = event.name = "bar"
608 pkgs = event.pkgs = ["foo"]
609 self.assertEqual(event.name, name)
610 self.assertEqual(event.pkgs, pkgs)
611 self.assertEqual(event.getFailures(), 0)
612 self.assertEqual(event.pid, EventClassesTest._worker_pid)
613
614 def test_BuildStarted(self):
615 """ Test class for build started events """
616 name = "foo"
617 pkgs = ["bar"]
618 failures = 123
619 event = bb.event.BuildStarted(name, pkgs, failures)
620 self.assertEqual(event.name, name)
621 self.assertEqual(event.pkgs, pkgs)
622 self.assertEqual(event.getFailures(), failures)
623 self.assertEqual(event.msg, "Building Started")
624 name = event.name = "bar"
625 pkgs = event.pkgs = ["foo"]
626 msg = event.msg = "foobar"
627 self.assertEqual(event.name, name)
628 self.assertEqual(event.pkgs, pkgs)
629 self.assertEqual(event.getFailures(), failures)
630 self.assertEqual(event.msg, msg)
631 self.assertEqual(event.pid, EventClassesTest._worker_pid)
632
633 def test_BuildCompleted(self):
634 """ Test class for build completed events """
635 total = 1000
636 name = "foo"
637 pkgs = ["bar"]
638 failures = 123
639 interrupted = 1
640 event = bb.event.BuildCompleted(total, name, pkgs, failures,
641 interrupted)
642 self.assertEqual(event.name, name)
643 self.assertEqual(event.pkgs, pkgs)
644 self.assertEqual(event.getFailures(), failures)
645 self.assertEqual(event.msg, "Building Failed")
646 event2 = bb.event.BuildCompleted(total, name, pkgs)
647 self.assertEqual(event2.name, name)
648 self.assertEqual(event2.pkgs, pkgs)
649 self.assertEqual(event2.getFailures(), 0)
650 self.assertEqual(event2.msg, "Building Succeeded")
651 self.assertEqual(event2.pid, EventClassesTest._worker_pid)
652
653 def test_DiskFull(self):
654 """ Test DiskFull event class """
655 dev = "/dev/foo"
656 type = "ext4"
657 freespace = "104M"
658 mountpoint = "/"
659 event = bb.event.DiskFull(dev, type, freespace, mountpoint)
660 self.assertEqual(event.pid, EventClassesTest._worker_pid)
661
662 def test_MonitorDiskEvent(self):
663 """ Test MonitorDiskEvent class """
664 available_bytes = 10000000
665 free_bytes = 90000000
666 total_bytes = 1000000000
667 du = bb.event.DiskUsageSample(available_bytes, free_bytes,
668 total_bytes)
669 event = bb.event.MonitorDiskEvent(du)
670 self.assertEqual(event.disk_usage.available_bytes, available_bytes)
671 self.assertEqual(event.disk_usage.free_bytes, free_bytes)
672 self.assertEqual(event.disk_usage.total_bytes, total_bytes)
673 self.assertEqual(event.pid, EventClassesTest._worker_pid)
674
675 def test_NoProvider(self):
676 """ Test NoProvider event class """
677 item = "foobar"
678 event1 = bb.event.NoProvider(item)
679 self.assertEqual(event1.getItem(), item)
680 self.assertEqual(event1.isRuntime(), False)
681 self.assertEqual(str(event1), "Nothing PROVIDES 'foobar'")
682 runtime = True
683 dependees = ["foo", "bar"]
684 reasons = None
685 close_matches = ["foibar", "footbar"]
686 event2 = bb.event.NoProvider(item, runtime, dependees, reasons,
687 close_matches)
688 self.assertEqual(event2.isRuntime(), True)
689 expected = ("Nothing RPROVIDES 'foobar' (but foo, bar RDEPENDS"
690 " on or otherwise requires it). Close matches:\n"
691 " foibar\n"
692 " footbar")
693 self.assertEqual(str(event2), expected)
694 reasons = ["Item does not exist on database"]
695 close_matches = ["foibar", "footbar"]
696 event3 = bb.event.NoProvider(item, runtime, dependees, reasons,
697 close_matches)
698 expected = ("Nothing RPROVIDES 'foobar' (but foo, bar RDEPENDS"
699 " on or otherwise requires it)\n"
700 "Item does not exist on database")
701 self.assertEqual(str(event3), expected)
702 self.assertEqual(event3.pid, EventClassesTest._worker_pid)
703
704 def test_MultipleProviders(self):
705 """ Test MultipleProviders event class """
706 item = "foobar"
707 candidates = ["foobarv1", "foobars"]
708 event1 = bb.event.MultipleProviders(item, candidates)
709 self.assertEqual(event1.isRuntime(), False)
710 self.assertEqual(event1.getItem(), item)
711 self.assertEqual(event1.getCandidates(), candidates)
712 expected = ("Multiple providers are available for foobar (foobarv1,"
713 " foobars)\n"
714 "Consider defining a PREFERRED_PROVIDER entry to match "
715 "foobar")
716 self.assertEqual(str(event1), expected)
717 runtime = True
718 event2 = bb.event.MultipleProviders(item, candidates, runtime)
719 self.assertEqual(event2.isRuntime(), runtime)
720 expected = ("Multiple providers are available for runtime foobar "
721 "(foobarv1, foobars)\n"
722 "Consider defining a PREFERRED_RPROVIDER entry to match "
723 "foobar")
724 self.assertEqual(str(event2), expected)
725 self.assertEqual(event2.pid, EventClassesTest._worker_pid)
726
727 def test_ParseStarted(self):
728 """ Test ParseStarted event class """
729 total = 123
730 event = bb.event.ParseStarted(total)
731 self.assertEqual(event.msg, "Recipe parsing Started")
732 self.assertEqual(event.total, total)
733 self.assertEqual(event.pid, EventClassesTest._worker_pid)
734
735 def test_ParseCompleted(self):
736 """ Test ParseCompleted event class """
737 cached = 10
738 parsed = 13
739 skipped = 7
740 virtuals = 2
741 masked = 1
742 errors = 0
743 total = 23
744 event = bb.event.ParseCompleted(cached, parsed, skipped, masked,
745 virtuals, errors, total)
746 self.assertEqual(event.msg, "Recipe parsing Completed")
747 expected = [cached, parsed, skipped, virtuals, masked, errors,
748 cached + parsed, total]
749 actual = [event.cached, event.parsed, event.skipped, event.virtuals,
750 event.masked, event.errors, event.sofar, event.total]
751 self.assertEqual(str(actual), str(expected))
752 self.assertEqual(event.pid, EventClassesTest._worker_pid)
753
754 def test_ParseProgress(self):
755 """ Test ParseProgress event class """
756 current = 10
757 total = 100
758 event = bb.event.ParseProgress(current, total)
759 self.assertEqual(event.msg,
760 "Recipe parsing" + ": %s/%s" % (current, total))
761 self.assertEqual(event.pid, EventClassesTest._worker_pid)
762
763 def test_CacheLoadStarted(self):
764 """ Test CacheLoadStarted event class """
765 total = 123
766 event = bb.event.CacheLoadStarted(total)
767 self.assertEqual(event.msg, "Loading cache Started")
768 self.assertEqual(event.total, total)
769 self.assertEqual(event.pid, EventClassesTest._worker_pid)
770
771 def test_CacheLoadProgress(self):
772 """ Test CacheLoadProgress event class """
773 current = 10
774 total = 100
775 event = bb.event.CacheLoadProgress(current, total)
776 self.assertEqual(event.msg,
777 "Loading cache" + ": %s/%s" % (current, total))
778 self.assertEqual(event.pid, EventClassesTest._worker_pid)
779
780 def test_CacheLoadCompleted(self):
781 """ Test CacheLoadCompleted event class """
782 total = 23
783 num_entries = 12
784 event = bb.event.CacheLoadCompleted(total, num_entries)
785 self.assertEqual(event.msg, "Loading cache Completed")
786 expected = [total, num_entries]
787 actual = [event.total, event.num_entries]
788 self.assertEqual(str(actual), str(expected))
789 self.assertEqual(event.pid, EventClassesTest._worker_pid)
790
791 def test_TreeDataPreparationStarted(self):
792 """ Test TreeDataPreparationStarted event class """
793 event = bb.event.TreeDataPreparationStarted()
794 self.assertEqual(event.msg, "Preparing tree data Started")
795 self.assertEqual(event.pid, EventClassesTest._worker_pid)
796
797 def test_TreeDataPreparationProgress(self):
798 """ Test TreeDataPreparationProgress event class """
799 current = 10
800 total = 100
801 event = bb.event.TreeDataPreparationProgress(current, total)
802 self.assertEqual(event.msg,
803 "Preparing tree data" + ": %s/%s" % (current, total))
804 self.assertEqual(event.pid, EventClassesTest._worker_pid)
805
806 def test_TreeDataPreparationCompleted(self):
807 """ Test TreeDataPreparationCompleted event class """
808 total = 23
809 event = bb.event.TreeDataPreparationCompleted(total)
810 self.assertEqual(event.msg, "Preparing tree data Completed")
811 self.assertEqual(event.total, total)
812 self.assertEqual(event.pid, EventClassesTest._worker_pid)
813
814 def test_DepTreeGenerated(self):
815 """ Test DepTreeGenerated event class """
816 depgraph = Mock()
817 event = bb.event.DepTreeGenerated(depgraph)
818 self.assertEqual(event.pid, EventClassesTest._worker_pid)
819
820 def test_TargetsTreeGenerated(self):
821 """ Test TargetsTreeGenerated event class """
822 model = Mock()
823 event = bb.event.TargetsTreeGenerated(model)
824 self.assertEqual(event.pid, EventClassesTest._worker_pid)
825
826 def test_ReachableStamps(self):
827 """ Test ReachableStamps event class """
828 stamps = [Mock(), Mock()]
829 event = bb.event.ReachableStamps(stamps)
830 self.assertEqual(event.stamps, stamps)
831 self.assertEqual(event.pid, EventClassesTest._worker_pid)
832
833 def test_FilesMatchingFound(self):
834 """ Test FilesMatchingFound event class """
835 pattern = "foo.*bar"
836 matches = ["foobar"]
837 event = bb.event.FilesMatchingFound(pattern, matches)
838 self.assertEqual(event.pid, EventClassesTest._worker_pid)
839
840 def test_ConfigFilesFound(self):
841 """ Test ConfigFilesFound event class """
842 variable = "FOO_BAR"
843 values = ["foo", "bar"]
844 event = bb.event.ConfigFilesFound(variable, values)
845 self.assertEqual(event.pid, EventClassesTest._worker_pid)
846
847 def test_ConfigFilePathFound(self):
848 """ Test ConfigFilePathFound event class """
849 path = "/foo/bar"
850 event = bb.event.ConfigFilePathFound(path)
851 self.assertEqual(event.pid, EventClassesTest._worker_pid)
852
853 def test_message_classes(self):
854 """ Test message event classes """
855 msg = "foobar foo bar"
856 event = bb.event.MsgBase(msg)
857 self.assertEqual(event.pid, EventClassesTest._worker_pid)
858 event = bb.event.MsgDebug(msg)
859 self.assertEqual(event.pid, EventClassesTest._worker_pid)
860 event = bb.event.MsgNote(msg)
861 self.assertEqual(event.pid, EventClassesTest._worker_pid)
862 event = bb.event.MsgWarn(msg)
863 self.assertEqual(event.pid, EventClassesTest._worker_pid)
864 event = bb.event.MsgError(msg)
865 self.assertEqual(event.pid, EventClassesTest._worker_pid)
866 event = bb.event.MsgFatal(msg)
867 self.assertEqual(event.pid, EventClassesTest._worker_pid)
868 event = bb.event.MsgPlain(msg)
869 self.assertEqual(event.pid, EventClassesTest._worker_pid)
870
871 def test_LogExecTTY(self):
872 """ Test LogExecTTY event class """
873 msg = "foo bar"
874 prog = "foo.sh"
875 sleep_delay = 10
876 retries = 3
877 event = bb.event.LogExecTTY(msg, prog, sleep_delay, retries)
878 self.assertEqual(event.msg, msg)
879 self.assertEqual(event.prog, prog)
880 self.assertEqual(event.sleep_delay, sleep_delay)
881 self.assertEqual(event.retries, retries)
882 self.assertEqual(event.pid, EventClassesTest._worker_pid)
883
884 def _throw_zero_division_exception(self):
885 a = 1 / 0
886 return
887
888 def _worker_handler(self, event, d):
889 self._returned_event = event
890 return
891
892 def test_LogHandler(self):
893 """ Test LogHandler class """
894 logger = logging.getLogger("TestEventClasses")
895 logger.propagate = False
896 handler = bb.event.LogHandler(logging.INFO)
897 logger.addHandler(handler)
898 bb.event.worker_fire = self._worker_handler
899 try:
900 self._throw_zero_division_exception()
901 except ZeroDivisionError as ex:
902 logger.exception(ex)
903 event = self._returned_event
904 try:
905 pe = pickle.dumps(event)
906 newevent = pickle.loads(pe)
907 except:
908 self.fail('Logged event is not serializable')
909 self.assertEqual(event.taskpid, EventClassesTest._worker_pid)
910
911 def test_MetadataEvent(self):
912 """ Test MetadataEvent class """
913 eventtype = "footype"
914 eventdata = {"foo": "bar"}
915 event = bb.event.MetadataEvent(eventtype, eventdata)
916 self.assertEqual(event.type, eventtype)
917 self.assertEqual(event.pid, EventClassesTest._worker_pid)
918
919 def test_ProcessStarted(self):
920 """ Test ProcessStarted class """
921 processname = "foo"
922 total = 9783128974
923 event = bb.event.ProcessStarted(processname, total)
924 self.assertEqual(event.processname, processname)
925 self.assertEqual(event.total, total)
926 self.assertEqual(event.pid, EventClassesTest._worker_pid)
927
928 def test_ProcessProgress(self):
929 """ Test ProcessProgress class """
930 processname = "foo"
931 progress = 243224
932 event = bb.event.ProcessProgress(processname, progress)
933 self.assertEqual(event.processname, processname)
934 self.assertEqual(event.progress, progress)
935 self.assertEqual(event.pid, EventClassesTest._worker_pid)
936
937 def test_ProcessFinished(self):
938 """ Test ProcessFinished class """
939 processname = "foo"
940 total = 1242342344
941 event = bb.event.ProcessFinished(processname)
942 self.assertEqual(event.processname, processname)
943 self.assertEqual(event.pid, EventClassesTest._worker_pid)
944
945 def test_SanityCheck(self):
946 """ Test SanityCheck class """
947 event1 = bb.event.SanityCheck()
948 self.assertEqual(event1.generateevents, True)
949 self.assertEqual(event1.pid, EventClassesTest._worker_pid)
950 generateevents = False
951 event2 = bb.event.SanityCheck(generateevents)
952 self.assertEqual(event2.generateevents, generateevents)
953 self.assertEqual(event2.pid, EventClassesTest._worker_pid)
954
955 def test_SanityCheckPassed(self):
956 """ Test SanityCheckPassed class """
957 event = bb.event.SanityCheckPassed()
958 self.assertEqual(event.pid, EventClassesTest._worker_pid)
959
960 def test_SanityCheckFailed(self):
961 """ Test SanityCheckFailed class """
962 msg = "The sanity test failed."
963 event1 = bb.event.SanityCheckFailed(msg)
964 self.assertEqual(event1.pid, EventClassesTest._worker_pid)
965 network_error = True
966 event2 = bb.event.SanityCheckFailed(msg, network_error)
967 self.assertEqual(event2.pid, EventClassesTest._worker_pid)
968
969 def test_network_event_classes(self):
970 """ Test network event classes """
971 event1 = bb.event.NetworkTest()
972 generateevents = False
973 self.assertEqual(event1.pid, EventClassesTest._worker_pid)
974 event2 = bb.event.NetworkTest(generateevents)
975 self.assertEqual(event2.pid, EventClassesTest._worker_pid)
976 event3 = bb.event.NetworkTestPassed()
977 self.assertEqual(event3.pid, EventClassesTest._worker_pid)
978 event4 = bb.event.NetworkTestFailed()
979 self.assertEqual(event4.pid, EventClassesTest._worker_pid)
980
981 def test_FindSigInfoResult(self):
982 """ Test FindSigInfoResult event class """
983 result = [Mock()]
984 event = bb.event.FindSigInfoResult(result)
985 self.assertEqual(event.result, result)
986 self.assertEqual(event.pid, EventClassesTest._worker_pid)