]> granicus.if.org Git - esp-idf/commitdiff
partition_table: Check - partition names must be unique
authorKonstantin Kondrashov <konstantin@espressif.com>
Wed, 5 Sep 2018 17:11:59 +0000 (01:11 +0800)
committerKonstantin Kondrashov <konstantin@espressif.com>
Wed, 12 Sep 2018 02:58:38 +0000 (10:58 +0800)
components/partition_table/gen_esp32part.py
components/partition_table/test_gen_esp32part_host/gen_esp32part_tests.py

index 7124559d3b27de4ce64d134ad068fb8252cfc026..66f5b30b07f2683d7d7e7bdbf6907939c407557e 100755 (executable)
@@ -169,6 +169,19 @@ class PartitionTable(list):
         # verify each partition individually
         for p in self:
             p.verify()
+        
+        # check on duplicate name
+        names = [ p.name for p in self ]
+        duplicates = set( n for n in names if names.count(n) > 1 )
+        
+        # print sorted duplicate partitions by name
+        if len(duplicates) != 0:
+            print("A list of partitions that have the same name:")
+            for p in sorted(self, key=lambda x:x.name):
+                if len(duplicates.intersection([p.name])) != 0:
+                    print("%s" % (p.to_csv()))
+            raise InputError("Partition names must be unique")
+        
         # check for overlaps
         last = None
         for p in sorted(self, key=lambda x:x.offset):
index 9f50f24652cffc31a7442c0c8ab865f1fd5e7ef4..7f3c79d16a427408ae43ab2eff3345da00ed98dc 100755 (executable)
@@ -166,6 +166,15 @@ second, app, ota_0,  0x200000, 1M
             t = PartitionTable.from_csv(csv)
             t.verify()
 
+    def test_unique_name_fail(self):
+        csv = """
+first, app, factory, 0x100000, 1M
+first, app, ota_0,  0x200000, 1M
+"""
+        with self.assertRaisesRegexp(InputError, "Partition names must be unique"):
+            t = PartitionTable.from_csv(csv)
+            t.verify()
+            
 class BinaryOutputTests(unittest.TestCase):
     def test_binary_entry(self):
         csv = """