Add macro to check if swap_type is an upgrade

This allows refactoring a check that was done in multiple places looking
for the same swap types.

Also fixes an issue where dependency checks would be run if a swap type
had a value that indicates fail.

Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index d01a71d..1634312 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -958,10 +958,7 @@
     int rc;
 
     swap_type = boot_swap_type_multi(BOOT_CURR_IMG(state));
-    switch (swap_type) {
-    case BOOT_SWAP_TYPE_TEST:
-    case BOOT_SWAP_TYPE_PERM:
-    case BOOT_SWAP_TYPE_REVERT:
+    if (BOOT_IS_UPGRADE(swap_type)) {
         /* Boot loader wants to switch to the secondary slot.
          * Ensure image is valid.
          */
@@ -2047,9 +2044,7 @@
         }
     }
 
-    if (swap_type == BOOT_SWAP_TYPE_TEST ||
-            swap_type == BOOT_SWAP_TYPE_PERM ||
-            swap_type == BOOT_SWAP_TYPE_REVERT) {
+    if (BOOT_IS_UPGRADE(swap_type)) {
         rc = boot_set_copy_done(BOOT_CURR_IMG(state));
         if (rc != 0) {
             BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_PANIC;
@@ -2093,9 +2088,7 @@
         }
     }
 
-    if (bs->swap_type == BOOT_SWAP_TYPE_TEST ||
-        bs->swap_type == BOOT_SWAP_TYPE_PERM ||
-        bs->swap_type == BOOT_SWAP_TYPE_REVERT) {
+    if (BOOT_IS_UPGRADE(bs->swap_type)) {
         rc = boot_set_copy_done(BOOT_CURR_IMG(state));
         if (rc != 0) {
             BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_PANIC;
@@ -2359,7 +2352,7 @@
         /* Determine swap type and complete swap if it has been aborted. */
         boot_prepare_image_for_update(state, &bs);
 
-        if (BOOT_SWAP_TYPE(state) != BOOT_SWAP_TYPE_NONE) {
+        if (BOOT_IS_UPGRADE(BOOT_SWAP_TYPE(state))) {
             has_upgrade = true;
         }
     }